﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using eService.Presentation;
using System.Management;

namespace eService.Presentation
{
    public partial class frmBanHang : Form
    {
        internal class clsGeneral
        {
            public static string currUserName;
            public static string currFullName;
            public static string currPwd;
            public static string iconWidth;
            public static string iconHeight;
            public static string TimeTypeReport;
            public static string ViewAndPrintBill;
            public static string sqlConnectionString;
            public static int roundValue;
            public static bool MakeBillWhenInput;
            public static bool BillShort;
            public static bool CusVIP;
            public static bool Pause;
            public static bool ShowUserCreate;
            public clsGeneral()
            {
                Func func = new Func();
                clsGeneral.sqlConnectionString = func.strConnectionString;
                try
                {
                    clsGeneral.iconWidth = ConfigurationSettings.AppSettings["IconWidth"].ToString();
                }
                catch
                {
                    clsGeneral.iconWidth = "90";
                }
                try
                {
                    clsGeneral.iconHeight = ConfigurationSettings.AppSettings["IconHeight"].ToString();
                }
                catch
                {
                    clsGeneral.iconHeight = "80";
                }
                try
                {
                    clsGeneral.TimeTypeReport = ConfigurationSettings.AppSettings["TimeTypeReport"].ToString();
                }
                catch
                {
                    clsGeneral.TimeTypeReport = "80";
                }
                try
                {
                    clsGeneral.ViewAndPrintBill = ConfigurationSettings.AppSettings["ViewAndPrintBill"].ToString();
                }
                catch
                {
                    clsGeneral.ViewAndPrintBill = "False";
                }
                try
                {
                    clsGeneral.roundValue = int.Parse(ConfigurationSettings.AppSettings["RoundValue"].ToString());
                }
                catch
                {
                    clsGeneral.roundValue = 1;
                }
                try
                {
                    clsGeneral.MakeBillWhenInput = bool.Parse(ConfigurationSettings.AppSettings["MakeBillWhenInput"].ToString());
                }
                catch
                {
                }
                try
                {
                    clsGeneral.BillShort = bool.Parse(ConfigurationSettings.AppSettings["BillShort"].ToString());
                }
                catch
                {
                    clsGeneral.BillShort = false;
                }
                try
                {
                    clsGeneral.CusVIP = bool.Parse(ConfigurationSettings.AppSettings["CusVIP"].ToString());
                }
                catch
                {
                    clsGeneral.CusVIP = false;
                }
                try
                {
                    clsGeneral.Pause = bool.Parse(ConfigurationSettings.AppSettings["Pause"].ToString());
                }
                catch
                {
                    clsGeneral.Pause = false;
                }
                try
                {
                    clsGeneral.ShowUserCreate = bool.Parse(ConfigurationSettings.AppSettings["UserCreate"].ToString());
                }
                catch
                {
                }
            }
            public static void SaveLog(string tempUserName, string objectName, string Note)
            {
                Func func = new Func();
                SqlConnection sqlConnection = new SqlConnection(func.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand("InsertIntoTabLog", sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@EmpID", SqlDbType.VarChar, 50);
                sqlCommand.Parameters.Add("@RoomName", SqlDbType.NVarChar, 200);
                sqlCommand.Parameters.Add("@TimeLog", SqlDbType.DateTime);
                sqlCommand.Parameters.Add("@Note", SqlDbType.NVarChar, 300);
                sqlCommand.Parameters["@EmpID"].Value = tempUserName;
                sqlCommand.Parameters["@RoomName"].Value = objectName;
                sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
                sqlCommand.Parameters["@Note"].Value = Note;
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            public static double roundMoney(double money, int roundValue)
            {
                double result;
                if (money % (double)roundValue != 0.0)
                {
                    result = (double)((int)money / roundValue * roundValue + roundValue);
                }
                else
                {
                    result = money;
                }
                return result;
            }
        }
        internal class Func
        {
            private string[] numberArr = new string[10];
            private string[] moneyArr = new string[4];
            public string strConnectionString = "";
            public Func()
            {
                this.strConnectionString = this.GetStrConnectionString();
            }
            public bool CheckPerDetailt(string Per, string UserName)
            {
                bool result = false;
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT * FROM TabUserPerDetailt WHERE Per = @Per AND UserName = @UserName";
                sqlCommand.Parameters.Add("Per", SqlDbType.VarChar).Value = Per;
                sqlCommand.Parameters.Add("UserName", SqlDbType.VarChar).Value = UserName;
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    result = true;
                }
                sqlDataReader.Close();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string GetSysPerByUserName(string UserName)
            {
                string text = "";
                string text2 = "";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT [Group] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        text = sqlDataReader["Group"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                if (text != "")
                {
                    text = "(" + text.Replace("\"", "") + ")";
                    SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
                    sqlCommand2.CommandText = "SELECT [GPer] FROM [TabGroup] WHERE [GID] IN" + text;
                    SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
                    while (sqlDataReader2.Read())
                    {
                        text2 = text2 + sqlDataReader2["GPer"].ToString() + ",";
                    }
                    sqlDataReader2.Close();
                    sqlDataReader2.Dispose();
                    if (text2 != "")
                    {
                        text2 = "IN(" + text2.Remove(text2.Length - 1, 1).Replace("\"", "") + ")";
                    }
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return text2;
            }
            public DataTable EXESelect(string strSQL)
            {
                DataTable dataTable = new DataTable();
                DataTable result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(strSQL, sqlConnection);
                    DataSet dataSet = new DataSet();
                    sqlDataAdapter.Fill(dataSet);
                    dataTable = dataSet.Tables[0];
                    sqlConnection.Close();
                    result = dataTable;
                }
                catch
                {
                    result = null;
                }
                return result;
            }
            public DataTable EXESelect(string Storedname, SqlParameter[] Parmeterarray)
            {
                DataTable dataTable = new DataTable();
                DataTable result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = new SqlCommand(Storedname, sqlConnection);
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.AddRange(Parmeterarray);
                    sqlCommand.CommandTimeout = 100;
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
                    DataSet dataSet = new DataSet();
                    sqlDataAdapter.Fill(dataSet);
                    dataTable = dataSet.Tables[0];
                    sqlConnection.Close();
                    result = dataTable;
                }
                catch
                {
                    result = null;
                }
                return result;
            }
            public SqlDataAdapter EXEAdapter(string Storedname, SqlParameter[] Parmeterarray)
            {
                SqlDataAdapter result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = new SqlCommand(Storedname, sqlConnection);
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.AddRange(Parmeterarray);
                    sqlCommand.CommandTimeout = 100;
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
                    sqlConnection.Close();
                    result = sqlDataAdapter;
                }
                catch
                {
                    result = null;
                }
                return result;
            }
            public bool EXEUpdate(string strSQL)
            {
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = strSQL;
                sqlCommand.CommandType = CommandType.Text;
                sqlCommand.CommandTimeout = 100;
                bool result;
                try
                {
                    int num = sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    result = true;
                }
                catch
                {
                    result = false;
                }
                return result;
            }
            public bool EXEUpdate(string Storedname, SqlParameter[] Parmeterarray)
            {
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand(Storedname, sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.AddRange(Parmeterarray);
                sqlCommand.CommandTimeout = 100;
                bool result;
                try
                {
                    int num = sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    result = true;
                }
                catch
                {
                    result = false;
                }
                return result;
            }
            public string Get_EXESelect(string strSQL)
            {
                DataTable dataTable = new DataTable();
                string result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(strSQL, sqlConnection);
                    DataSet dataSet = new DataSet();
                    sqlDataAdapter.Fill(dataSet);
                    dataTable = dataSet.Tables[0];
                    sqlConnection.Close();
                    if (dataTable.Rows.Count > 0)
                    {
                        result = dataTable.Rows[0][0].ToString();
                    }
                    else
                    {
                        result = "";
                    }
                }
                catch
                {
                    result = "";
                }
                return result;
            }
            public int Get_EXESelectInt(string strSQL)
            {
                DataTable dataTable = new DataTable();
                int result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(strSQL, sqlConnection);
                    DataSet dataSet = new DataSet();
                    sqlDataAdapter.Fill(dataSet);
                    dataTable = dataSet.Tables[0];
                    sqlConnection.Close();
                    if (dataTable.Rows.Count > 0)
                    {
                        result = int.Parse(dataTable.Rows[0][0].ToString());
                    }
                    else
                    {
                        result = 0;
                    }
                }
                catch
                {
                    result = 0;
                }
                return result;
            }
            public double getFistBalanceProvider(string pID)
            {
                double result = 0.0;
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                string cmdText = "SELECT ISNULL([First],0) AS Value FROM [tblPartner] WHERE [ID] =" + pID;
                SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        result = double.Parse(sqlDataReader["Value"].ToString());
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public double getTotalMoney(string pID, DateTime pointDate, int TypePartner)
            {
                double result = 0.0;
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlParameter sqlParameter = new SqlParameter("objDate", SqlDbType.DateTime);
                sqlParameter.Value = pointDate;
                string cmdText;
                if (TypePartner == 1)
                {
                    cmdText = "SELECT SUM(CASE WHEN [TypeInput]=1 THEN (-[TotalMoney]) WHEN [TypeInput]=2 THEN ([TotalMoney]) END) AS MySum FROM [tblBill] WHERE ([TotalMoney])<>0 AND ([TypeInput]=1 OR [TypeInput]=2 ) and [PartnerID] =" + pID + " AND [billDate] <@objDate";
                }
                else
                {
                    cmdText = "SELECT SUM([TotalMoney]-[TotalPay]-[DiscountMoney]-[MoneyDiscountPercent]) AS MySum FROM [TabRepList] WHERE ([TotalMoney]-[TotalPay]-[DiscountMoney]-[MoneyDiscountPercent])<>0 AND [PatnerID] =" + pID + " AND [DateReal] <@objDate";
                }
                SqlDataReader sqlDataReader = new SqlCommand(cmdText, sqlConnection)
                {
                    Parameters = 
				{
					sqlParameter
				}
                }.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        try
                        {
                            result = double.Parse(sqlDataReader["MySum"].ToString());
                        }
                        catch
                        {
                            result = 0.0;
                        }
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public void SetFocusListView(ListView lv, int tmpIndex)
            {
                if (lv.Items.Count > 0)
                {
                    for (int i = 0; i < lv.Items.Count; i++)
                    {
                        if (i != tmpIndex)
                        {
                            lv.Items[i].Selected = false;
                            lv.Items[i].Checked = false;
                        }
                    }
                    lv.Items[tmpIndex].Selected = true;
                    lv.Items[tmpIndex].Checked = true;
                    lv.Items[tmpIndex].EnsureVisible();
                }
            }
            public string GetStrConnectionString()
            {
                string text = ConfigurationSettings.AppSettings["ServerName"].ToString();
                string text2 = ConfigurationSettings.AppSettings["UserID"].ToString();
                string text3 = ConfigurationSettings.AppSettings["PassWord"].ToString();
                string text4 = ConfigurationSettings.AppSettings["DataBase"].ToString();
                return string.Concat(new string[]
			{
				"Server=",
				text,
				"; Initial Catalog=",
				text4,
				"; User Id=",
				text2,
				"; pwd=",
				text3,
				";"
			});
            }
            public int updateConfig(int TypeDate, string objTime)
            {
                int result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = new SqlCommand("ActionOnTabConfigDate", sqlConnection);
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.Add("TypeDate", SqlDbType.SmallInt);
                    sqlCommand.Parameters.Add("PointDate", SqlDbType.VarChar, 500);
                    sqlCommand.Parameters["TypeDate"].Value = TypeDate;
                    sqlCommand.Parameters["PointDate"].Value = objTime;
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                    result = 0;
                }
                catch
                {
                    result = 1;
                }
                return result;
            }
            public string DateFormating(string InputStr)
            {
                string result;
                try
                {
                    DateTime.Parse("12/15/2009");
                    string text;
                    if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(3, 1) == "/")
                    {
                        text = string.Concat(new string[]
					{
						"0",
						InputStr.Substring(2, 1),
						"/0",
						InputStr.Substring(0, 1),
						"/",
						InputStr.Substring(4, 4)
					});
                    }
                    else
                    {
                        if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(4, 1) == "/")
                        {
                            text = string.Concat(new string[]
						{
							"0",
							InputStr.Substring(3, 1),
							"/",
							InputStr.Substring(0, 2),
							"/",
							InputStr.Substring(5, 4)
						});
                        }
                        else
                        {
                            if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(4, 1) == "/")
                            {
                                text = string.Concat(new string[]
							{
								InputStr.Substring(2, 2),
								"/0",
								InputStr.Substring(0, 1),
								"/",
								InputStr.Substring(5, 4)
							});
                            }
                            else
                            {
                                if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(5, 1) == "/")
                                {
                                    text = string.Concat(new string[]
								{
									InputStr.Substring(3, 2),
									"/",
									InputStr.Substring(0, 2),
									"/",
									InputStr.Substring(6, 4)
								});
                                }
                                else
                                {
                                    text = InputStr;
                                }
                            }
                        }
                    }
                    result = text;
                }
                catch
                {
                    result = DateTime.Parse(InputStr).ToShortDateString();
                }
                return result;
            }
            public DateTime getMaxDateBeforeNowOnTabReportDaily()
            {
                DateTime result = DateTime.Now;
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT Max(daily) as day from tabReportDaily where [daily]<@DT ";
                sqlCommand.Parameters.AddWithValue("@DT", DateTime.Now.ToShortDateString());
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        try
                        {
                            result = DateTime.Parse(sqlDataReader["day"].ToString());
                        }
                        catch
                        {
                            result = DateTime.Now;
                        }
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string GetFullName(string UserName)
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT [FullName] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    result = sqlDataReader["FullName"].ToString();
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public int GetConfigPriceWhenChange()
            {
                int result = 0;
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT [PriceWhenChange] FROM [TabConfig] ";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        result = int.Parse(sqlDataReader["PriceWhenChange"].ToString());
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public void UpdateConfigPriceWhenChange(int tempValue)
            {
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "UPDATE  [TabConfig] SET [PriceWhenChange]=" + tempValue;
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            public string DateFormatingToWin(string InputStr)
            {
                string typeDate = this.getTypeDate();
                string result;
                if (typeDate == "1")
                {
                    if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(3, 1) == "/")
                    {
                        result = string.Concat(new string[]
					{
						"0",
						InputStr.Substring(2, 1),
						"/0",
						InputStr.Substring(0, 1),
						"/",
						InputStr.Substring(4, 4)
					});
                    }
                    else
                    {
                        if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(4, 1) == "/")
                        {
                            result = string.Concat(new string[]
						{
							"0",
							InputStr.Substring(3, 1),
							"/",
							InputStr.Substring(0, 2),
							"/",
							InputStr.Substring(5, 4)
						});
                        }
                        else
                        {
                            if (InputStr.Substring(1, 1) == "/" && InputStr.Substring(4, 1) == "/")
                            {
                                result = string.Concat(new string[]
							{
								InputStr.Substring(2, 2),
								"/0",
								InputStr.Substring(0, 1),
								"/",
								InputStr.Substring(5, 4)
							});
                            }
                            else
                            {
                                if (InputStr.Substring(2, 1) == "/" && InputStr.Substring(5, 1) == "/")
                                {
                                    result = string.Concat(new string[]
								{
									InputStr.Substring(3, 2),
									"/",
									InputStr.Substring(0, 2),
									"/",
									InputStr.Substring(6, 4)
								});
                                }
                                else
                                {
                                    result = InputStr.Substring(0, InputStr.IndexOf(":") - 3);
                                }
                            }
                        }
                    }
                }
                else
                {
                    result = InputStr.Substring(0, InputStr.IndexOf(":") - 3);
                }
                return result;
            }
            public string getTypeDate()
            {
                string text = "0";
                string result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.CommandText = "SELECT [TypeDate] FROM [TabConfigDate]";
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            text = sqlDataReader["TypeDate"].ToString();
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                    result = text;
                }
                catch
                {
                    result = "0";
                }
                return result;
            }
            public string getPointDate()
            {
                string text = "0";
                string result;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.CommandText = "SELECT [PointDate] FROM [TabConfigDate]";
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        text = sqlDataReader["PointDate"].ToString();
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                    result = text;
                }
                catch
                {
                    result = "0";
                }
                return result;
            }
            public string GetSysPer(string UserName, string PassWord)
            {
                string text = "";
                string text2 = "";
                bool flag = false;
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT [Group],[Pass] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read() && !flag)
                {
                    if (this.CryptographyMD5(PassWord) == sqlDataReader["Pass"].ToString())
                    {
                        text = sqlDataReader["Group"].ToString();
                        flag = true;
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                if (text != "")
                {
                    text = "(" + text.Replace("\"", "") + ")";
                    SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
                    sqlCommand2.CommandText = "SELECT [GPer] FROM [TabGroup] WHERE [GID] IN" + text;
                    SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
                    while (sqlDataReader2.Read())
                    {
                        text2 = text2 + sqlDataReader2["GPer"].ToString() + ",";
                    }
                    sqlDataReader2.Close();
                    sqlDataReader2.Dispose();
                    if (text2 != "")
                    {
                        text2 = "IN(" + text2.Remove(text2.Length - 1, 1).Replace("\"", "") + ")";
                    }
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return text2;
            }
            public string GetSysPer(string UserName)
            {
                string text = "";
                string text2 = "";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT [Group] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        text = sqlDataReader["Group"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                if (text != "")
                {
                    text = "(" + text.Replace("\"", "") + ")";
                    SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
                    sqlCommand2.CommandText = "SELECT [GPer] FROM [TabGroup] WHERE [GID] IN" + text;
                    SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
                    while (sqlDataReader2.Read())
                    {
                        text2 = text2 + sqlDataReader2["GPer"].ToString() + ",";
                    }
                    sqlDataReader2.Close();
                    sqlDataReader2.Dispose();
                    if (text2 != "")
                    {
                        text2 = "IN(" + text2.Remove(text2.Length - 1, 1).Replace("\"", "") + ")";
                    }
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return text2;
            }
            public string GetUserGroupNew(string UserName)
            {
                string text = "";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT [Group] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    text = sqlDataReader["Group"].ToString();
                    text = text.Replace("\"", "");
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return text;
            }
            public string CryptographyMD5(string source)
            {
                MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
                byte[] bytes = Encoding.UTF8.GetBytes(source);
                byte[] array = mD5CryptoServiceProvider.ComputeHash(bytes);
                string text = "";
                byte[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    byte b = array2[i];
                    text += int.Parse(b.ToString(), NumberStyles.HexNumber).ToString();
                }
                return text;
            }
            public string getValue(string tableName, string fieldName, string conditionName, string valueCompare)
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                string commandText = string.Concat(new string[]
			{
				"SELECT [",
				fieldName,
				"] FROM [",
				tableName,
				"] WHERE [",
				conditionName,
				"] = '",
				valueCompare,
				"'"
			});
                try
                {
                    sqlCommand.CommandText = commandText;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = sqlDataReader[fieldName].ToString();
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string getValueNumber(string objSQL, string fieldName)
            {
                string result = "0";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                try
                {
                    sqlCommand.CommandText = objSQL;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = sqlDataReader["" + fieldName + ""].ToString();
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public void LoadComboBox(string SQL, ComboBox objCbb, string _ValueNumber, string _ValueText)
            {
                objCbb.BindingContext = new BindingContext();
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQL, sqlConnection);
                DataSet dataSet = new DataSet();
                try
                {
                    sqlDataAdapter.Fill(dataSet);
                    objCbb.DataSource = dataSet.Tables[0].DefaultView;
                    objCbb.ValueMember = _ValueNumber;
                    objCbb.DisplayMember = _ValueText;
                    objCbb.SelectedIndex = 0;
                }
                catch
                {
                }
                finally
                {
                    dataSet.Dispose();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }
            public void SelectValueCombobox(ComboBox objCbb, string objValue)
            {
                for (int i = 0; i < objCbb.Items.Count; i++)
                {
                    ItemCombobox itemCombobox = (ItemCombobox)objCbb.Items[i];
                    if (itemCombobox.Value == objValue)
                    {
                        objCbb.SelectedIndex = i;
                        break;
                    }
                }
            }
            public void LoadAutoCompleteTextBox(string SQL, TextBox txt, string _ValueText)
            {
                AutoCompleteStringCollection autoCompleteStringCollection = new AutoCompleteStringCollection();
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = SQL;
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        autoCompleteStringCollection.Add(sqlDataReader[_ValueText].ToString());
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
                txt.AutoCompleteCustomSource = autoCompleteStringCollection;
            }
            public string VND(float NumCurrency)
            {
                string text = "";
                string text2 = "";
                string[] array = new string[10];
                int num = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                int num5 = 0;
                int num6 = 0;
                int num7 = 0;
                string text3 = "đồng";
                string text4 = "xu";
                if (NumCurrency != 0f)
                {
                    if ((double)NumCurrency <= 922337203685477.0)
                    {
                        array[1] = "một";
                        array[2] = "hai";
                        array[3] = "ba";
                        array[4] = "bốn";
                        array[5] = "năm";
                        array[6] = "sáu";
                        array[7] = "bảy";
                        array[8] = "tám";
                        array[9] = "chín";
                        num = (int)((NumCurrency - (float)((int)NumCurrency)) * 100f);
                        string text5 = NumCurrency.ToString().Trim();
                        string str = new string(' ', 15 - text5.Length);
                        text5 = str + text5;
                        try
                        {
                            num3 = int.Parse(text5.Substring(0, 3));
                        }
                        catch
                        {
                            num3 = 0;
                        }
                        try
                        {
                            num4 = int.Parse(text5.Substring(3, 3));
                        }
                        catch
                        {
                            num4 = 0;
                        }
                        try
                        {
                            num5 = int.Parse(text5.Substring(6, 3));
                        }
                        catch
                        {
                            num5 = 0;
                        }
                        try
                        {
                            num6 = int.Parse(text5.Substring(9, 3));
                        }
                        catch
                        {
                            num6 = 0;
                        }
                        try
                        {
                            num7 = int.Parse(text5.Substring(12, 3));
                        }
                        catch
                        {
                            num7 = 0;
                        }
                        int i;
                        if (num3 == 0 && num4 == 0 && num5 == 0 && num6 == 0 && num7 == 0)
                        {
                            text2 = "Không " + text3;
                            i = 5;
                        }
                        else
                        {
                            text2 = "";
                            i = 0;
                        }
                        while (i <= 5)
                        {
                            switch (i)
                            {
                                case 0:
                                    num2 = num3;
                                    text = "nghìn tỷ ";
                                    break;
                                case 1:
                                    num2 = num4;
                                    text = "tỷ ";
                                    break;
                                case 2:
                                    num2 = num5;
                                    text = "triệu ";
                                    break;
                                case 3:
                                    num2 = num6;
                                    text = "nghìn";
                                    break;
                                case 4:
                                    num2 = num7;
                                    text = text3;
                                    break;
                                case 5:
                                    num2 = num;
                                    text = text4;
                                    break;
                            }
                            if (num2 != 0)
                            {
                                int num8 = num2 / 100;
                                int num9 = (num2 - num8 * 100) / 10;
                                int num10 = num2 - num8 * 100 - num9 * 10;
                                text2 = text2.Trim() + ((text2.Length == 0) ? "" : " ") + ((num8 != 0) ? (array[num8].Trim() + " trăm ") : " không trăm ");
                                if (num9 == 0 & num8 != 0 & num10 != 0)
                                {
                                    text2 += "lẻ ";
                                }
                                else
                                {
                                    if (num9 != 0)
                                    {
                                        text2 += ((num9 != 0 & num9 != 1) ? (array[num9].Trim() + " mười ") : "mười ");
                                    }
                                }
                                if (num9 != 0 & num10 == 5)
                                {
                                    text2 = text2 + "lăm " + text + " ";
                                }
                                else
                                {
                                    if (num9 > 1 & num10 == 1)
                                    {
                                        text2 = text2 + "mốt " + text + " ";
                                    }
                                    else
                                    {
                                        text2 += ((num10 != 0) ? (array[num10].Trim() + " " + text + " ") : (text + " "));
                                    }
                                }
                            }
                            else
                            {
                                text2 += ((i == 4) ? (text3 + " ") : "");
                            }
                            i++;
                        }
                    }
                }
                return text2;
            }
            public string getSumInput(string productID, string objWH)
            {
                string commandText = string.Concat(new string[]
			{
				"SELECT [lastBalance] FROM [TabWareProduct] WHERE [Pid] = ",
				productID,
				" AND WhId='",
				objWH,
				"'"
			});
                string text = "0";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = commandText;
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    text = sqlDataReader["lastBalance"].ToString();
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                if (text.Length == 0)
                {
                    text = "0";
                }
                return text;
            }
            public string Convert2SQLDateTime24(string sDate)
            {
                string result;
                try
                {
                    DateTime.Parse("12/15/2009");
                    result = "CONVERT(DATETIME, '" + sDate + " 12:00:00 AM', 102)";
                }
                catch
                {
                    result = "CONVERT(DATETIME, '" + sDate + " 12:00:00 AM', 103)";
                }
                return result;
            }
            public string getSumInput(string productID, string provideID, string month, string year)
            {
                string commandText = "SELECT SUM(Number) AS SUMNUMBER FROM [TabRepList],[TabRepLink] WHERE [TabRepList].[RepID] = [TabRepLink].[RepID]  AND [RepProID] = '" + provideID + "' AND [Pid] = " + productID;
                string text = "0";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = commandText;
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    text = sqlDataReader["SUMNUMBER"].ToString();
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                if (text.Length == 0)
                {
                    text = "0";
                }
                return text;
            }
            public string getSumOutput(string productID, string provideID, string month, string year)
            {
                string commandText = string.Concat(new string[]
			{
				"SELECT SUM(Number) AS SUMNUMBER FROM [TabReturnRepList],[TabReturnRepLink] WHERE [TabReturnRepList].[RepID] = [TabReturnRepLink].[RepID] AND datepart(m,RepDate) = ",
				month,
				" AND datepart(yyyy,RepDate) = ",
				year,
				" AND [RepProID] = '",
				provideID,
				"' AND [Pid] = ",
				productID
			});
                string text = "0";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = commandText;
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    text = sqlDataReader["SUMNUMBER"].ToString();
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                if (text.Length == 0)
                {
                    text = "0";
                }
                return text;
            }
            public string changeNumberToWord(float NumCurrency)
            {
                string text = "";
                string text2 = "";
                string[] array = new string[10];
                int num = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                int num5 = 0;
                int num6 = 0;
                int num7 = 0;
                int num8 = 0;
                int num9 = 0;
                int num10 = 0;
                string text3 = "Đồng";
                string text4 = "xu";
                if (NumCurrency != 0f)
                {
                    if ((double)NumCurrency <= 922337203685477.0)
                    {
                        array[1] = "Một";
                        array[2] = "Hai";
                        array[3] = "Ba";
                        array[4] = "Bốn";
                        array[5] = "Năm";
                        array[6] = "Sáu";
                        array[7] = "Bảy";
                        array[8] = "Tám";
                        array[9] = "Chín";
                        num = (int)((NumCurrency - (float)((int)NumCurrency)) * 100f);
                        string text5 = NumCurrency.ToString().Trim();
                        string str = new string(' ', 15 - text5.Length);
                        text5 = str + text5;
                        try
                        {
                            num3 = int.Parse(text5.Substring(0, 3));
                        }
                        catch
                        {
                            num3 = 0;
                        }
                        try
                        {
                            num4 = int.Parse(text5.Substring(3, 3));
                        }
                        catch
                        {
                            num4 = 0;
                        }
                        try
                        {
                            num5 = int.Parse(text5.Substring(6, 3));
                        }
                        catch
                        {
                            num5 = 0;
                        }
                        try
                        {
                            num6 = int.Parse(text5.Substring(9, 3));
                        }
                        catch
                        {
                            num6 = 0;
                        }
                        try
                        {
                            num7 = int.Parse(text5.Substring(12, 3));
                        }
                        catch
                        {
                            num7 = 0;
                        }
                        int i;
                        if (num3 == 0 && num4 == 0 && num5 == 0 && num6 == 0 && num7 == 0)
                        {
                            text2 = "Không " + text3;
                            i = 5;
                        }
                        else
                        {
                            text2 = "";
                            i = 0;
                        }
                        while (i <= 5)
                        {
                            switch (i)
                            {
                                case 0:
                                    num2 = num3;
                                    text = "Nghìn tỷ";
                                    break;
                                case 1:
                                    num2 = num4;
                                    text = "Tỷ ";
                                    break;
                                case 2:
                                    num2 = num5;
                                    text = "Triệu ";
                                    break;
                                case 3:
                                    num2 = num6;
                                    text = "Nghìn";
                                    break;
                                case 4:
                                    num2 = num7;
                                    text = text3;
                                    break;
                                case 5:
                                    num2 = num;
                                    text = text4;
                                    break;
                            }
                            if (num2 != 0)
                            {
                                num8 = num2 / 100;
                                num9 = (num2 - num8 * 100) / 10;
                                num10 = num2 - num8 * 100 - num9 * 10;
                                try
                                {
                                    text2 = text2.Trim() + ((text2.Length == 0) ? "" : " ") + ((num8 != 0) ? (array[num8].Trim() + " Trăm ") : "");
                                }
                                catch
                                {
                                }
                                if (num9 == 0 & num8 != 0 & num10 != 0)
                                {
                                    text2 += " Lẻ ";
                                }
                                else
                                {
                                    if (num9 != 0)
                                    {
                                        try
                                        {
                                            text2 += ((num9 != 0 & num9 != 1) ? (array[num9].Trim() + " Mười ") : "Mười ");
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                if (num9 != 0 & num10 == 5)
                                {
                                    text2 = text2 + "Lăm " + text + " ";
                                }
                                else
                                {
                                    if (num9 > 1 & num10 == 1)
                                    {
                                        text2 = text2 + "Mốt " + text + " ";
                                    }
                                    else
                                    {
                                        try
                                        {
                                            text2 += ((num10 != 0) ? (array[num10].Trim() + " " + text + " ") : (text + " "));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                            else
                            {
                                text2 += ((i == 4) ? (text3 + " ") : "");
                            }
                            i++;
                        }
                    }
                }
                return text2;
            }
            private string ChangeNumToWord(int NumVar)
            {
                string text = "";
                int num = int.Parse((NumVar / 100).ToString());
                int num2 = int.Parse((NumVar % 100 / 10).ToString());
                int num3 = NumVar % 10;
                if (num == 0 && num2 == 0 && num3 == 0)
                {
                    text = "";
                }
                if (num != 0)
                {
                    text = text + this.numberArr[num].ToString() + " Trăm ";
                    if (num2 == 0 && num3 != 0)
                    {
                        text += "Lẻ ";
                    }
                }
                if (num2 != 0 && num2 != 1)
                {
                    text = text + this.numberArr[num2].ToString() + " Mươi ";
                    if (num2 == 0 && num3 != 0)
                    {
                        text += " Lẻ ";
                    }
                }
                if (num2 == 1)
                {
                    text += " Mười ";
                }
                int num4 = num3;
                if (num4 != 1)
                {
                    if (num4 != 5)
                    {
                        text += this.numberArr[num3].ToString();
                    }
                    else
                    {
                        if (num2 == 0)
                        {
                            text += this.numberArr[num3].ToString();
                        }
                        else
                        {
                            text += " Lăm ";
                        }
                    }
                }
                else
                {
                    if (num2 != 0 && num2 != 1)
                    {
                        text += " Mốt ";
                    }
                    else
                    {
                        text += this.numberArr[num3].ToString();
                    }
                }
                return text;
            }
            public string changeNumberToWord1(long NumberChange)
            {
                string text = "";
                int[] array = new int[4];
                this.numberArr[0] = "";
                this.numberArr[1] = "Một ";
                this.numberArr[2] = "Hai ";
                this.numberArr[3] = "Ba ";
                this.numberArr[4] = "Bốn ";
                this.numberArr[5] = "Năm ";
                this.numberArr[6] = "Sáu ";
                this.numberArr[7] = "Bảy ";
                this.numberArr[8] = "Tám ";
                this.numberArr[9] = "Chín ";
                this.moneyArr[0] = "Đồng ";
                this.moneyArr[1] = "Ngàn ";
                this.moneyArr[2] = "Triệu ";
                this.moneyArr[3] = "Tỷ ";
                if (NumberChange < 0L)
                {
                    text = "Trừ ";
                }
                if (Math.Abs(NumberChange) > 999999999999L)
                {
                    NumberChange = 0L;
                }
                long num = Math.Abs(NumberChange);
                array[3] = int.Parse((num / 1000000000L).ToString());
                num -= long.Parse(array[3].ToString() + "000000000");
                array[2] = int.Parse((num / 1000000L).ToString());
                array[1] = int.Parse((num % 1000000L / 1000L).ToString());
                array[0] = int.Parse((num % 1000L).ToString());
                int num2;
                if (array[3] > 0)
                {
                    num2 = 3;
                }
                else
                {
                    if (array[2] > 0)
                    {
                        num2 = 2;
                    }
                    else
                    {
                        if (array[1] > 0)
                        {
                            num2 = 1;
                        }
                        else
                        {
                            num2 = 0;
                        }
                    }
                }
                for (int i = num2; i >= 0; i--)
                {
                    try
                    {
                        text += this.ChangeNumToWord(array[i]);
                    }
                    catch
                    {
                    }
                    text = text + this.moneyArr[i].ToString() + " ";
                }
                text = text.ToLower().Trim();
                text = text.Substring(0, 1).ToUpper() + text.Remove(0, 1);
                return text.Trim().Replace("  ", " ").Replace("triệu ngàn đồng", "triệu đồng").Replace("tỷ triệu ngàn đồng", "tỷ đồng");
            }
            public string Convert2SQLDateTime(string sDate)
            {
                string result;
                try
                {
                    DateTime.Parse("12/15/2009");
                    result = "CONVERT(DATETIME, '" + sDate + " 00:00:00', 102)";
                }
                catch
                {
                    result = "CONVERT(DATETIME, '" + sDate + " 00:00:00', 103)";
                }
                return result;
            }
            public string Convert2SQLDateTimesTART(string sDate)
            {
                string result;
                try
                {
                    DateTime.Parse("12/15/2009");
                    result = "CONVERT(DATETIME, '" + sDate + " 06:00:00 AM', 102)";
                }
                catch
                {
                    result = "CONVERT(DATETIME, '" + sDate + " 06:00:00 AM', 103)";
                }
                return result;
            }
            public string Convert2SQLDateTimesTOP(string sDate)
            {
                string result;
                try
                {
                    DateTime.Parse("12/15/2009");
                    result = "CONVERT(DATETIME, '" + sDate + " 00:00:00 AM', 102)";
                }
                catch
                {
                    result = "CONVERT(DATETIME, '" + sDate + " 00:00:00 AM', 103)";
                }
                return result;
            }
            public string Convert2SQLDateTime1(string sDate)
            {
                string result;
                try
                {
                    DateTime.Parse("12/15/2009");
                    result = "CONVERT(DATETIME, '" + sDate + " 12:00:00 AM', 102)";
                }
                catch
                {
                    result = "CONVERT(DATETIME, '" + sDate + " 12:00:00 AM', 103)";
                }
                return result;
            }
            public DataTable AutoNumberedTable(DataTable SourceTable)
            {
                DataTable dataTable = new DataTable();
                DataColumn dataColumn = new DataColumn();
                dataColumn.ColumnName = "TT";
                dataColumn.DataType = typeof(int);
                dataColumn.AutoIncrement = true;
                dataColumn.AutoIncrementSeed = 1L;
                dataColumn.AutoIncrementStep = 1L;
                dataTable.Columns.Add(dataColumn);
                dataTable.Merge(SourceTable);
                return dataTable;
            }
            public string getCompanyInfor(string Field)
            {
                string commandText = "SELECT " + Field + " FROM [TabCompany] WHERE [ComID] = 'COM01'";
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = commandText;
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    result = sqlDataReader[Field].ToString();
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public bool CheckForm(string FormName, Form objParent)
            {
                bool result = false;
                Form[] mdiChildren = objParent.MdiChildren;
                for (int i = 0; i < mdiChildren.Length; i++)
                {
                    Form form = mdiChildren[i];
                    if (FormName == form.Name.ToString())
                    {
                        result = true;
                        break;
                    }
                }
                return result;
            }
            public void FormActive(string FormName, Form objParent)
            {
                Form[] mdiChildren = objParent.MdiChildren;
                for (int i = 0; i < mdiChildren.Length; i++)
                {
                    Form form = mdiChildren[i];
                    if (FormName == form.Name.ToString())
                    {
                        form.Activate();
                        break;
                    }
                }
            }
            public void DefineArray(string[] ArrayName, int Count)
            {
                try
                {
                    for (int i = 0; i < Count; i++)
                    {
                        ArrayName[i] = "NULL";
                    }
                }
                catch
                {
                }
            }
            public void DefineArrayNumber(string[] ArrayName, int Count)
            {
                try
                {
                    for (int i = 0; i < Count; i++)
                    {
                        ArrayName[i] = "0";
                    }
                }
                catch
                {
                }
            }
            public int GetDVTQD(string objUnitID)
            {
                int result = 1;
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT UnitChild,UnitNumber FROM TabUnitProduct WHERE UnitID=" + objUnitID + "", sqlConnection);
                sqlConnection.Open();
                try
                {
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            if (sqlDataReader["UnitChild"].ToString() != "0")
                            {
                                result = int.Parse(sqlDataReader["UnitNumber"].ToString());
                            }
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public float GetServiceMoney(string RetailID)
            {
                float result = 0f;
                SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
                SqlCommand sqlCommand = new SqlCommand("SELECT SUM(TotalMoney)  as TotalMoney FROM TabRetailsLink WHERE [RetailID]='" + RetailID + "'", sqlConnection);
                sqlConnection.Open();
                try
                {
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            result = float.Parse(sqlDataReader["TotalMoney"].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string GetIDRoomForRetail()
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.GetStrConnectionString());
                SqlCommand sqlCommand = new SqlCommand("SELECT TOP 1 RID FROM TabRoom WHERE RPrice=0", sqlConnection);
                sqlConnection.Open();
                try
                {
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            result = sqlDataReader["RID"].ToString();
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                    result = "";
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string GetUserGroup(string UserName)
            {
                string text = "";
                SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT [Group] FROM [TabUser] WHERE [UserName] = '" + UserName + "'";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    text = sqlDataReader["Group"].ToString();
                    text = text.Replace("\"", "");
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return text;
            }
            public int getShowItemByGroup()
            {
                int result = 0;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.CommandText = "SELECT ISNULL(showItemByGroup,0) as showItemByGroup FROM TabConfig";
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = int.Parse(sqlDataReader["showItemByGroup"].ToString());
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
                return result;
            }
            public int getBillScrollType()
            {
                int result = 0;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.CommandText = "SELECT ISNULL(BillScrollType,0) as BillScrollType FROM TabConfig";
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = int.Parse(sqlDataReader["BillScrollType"].ToString());
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
                return result;
            }
        }
        internal class clsFormText
        {
            private Func objFunc = new Func();
            private string strConnection = "";
            public clsFormText()
            {
                this.strConnection = this.objFunc.strConnectionString;
            }
            public void resetData()
            {
                SqlConnection sqlConnection = new SqlConnection(this.strConnection);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                string text = "IF NOT EXISTS (SELECT [column_name] FROM information_schema.columns WHERE [table_name] = 'TabFormText')";
                text += "BEGIN CREATE TABLE TabFormText(Id int identity primary key, FormId nvarchar(50), FormDes nvarchar(200), ControlId nvarchar(50), ControlText1 nvarchar(250), ControlText2 nvarchar(250)) END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmBillScrollK501' AND ControlId = 'lblTieuDeTienphong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmBillScrollK501',N'Hóa đơn mẫu K57',N'lblTieuDeTienphong',N'Tiền sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmBillScrollK501' AND ControlId = 'lblTieuDeKMTienPhong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmBillScrollK501',N'Hóa đơn mẫu K57',N'lblTieuDeKMTienPhong',N'KM tiền sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmRetailBillScrollCus' AND ControlId = 'lblTieuDeTienphong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmRetailBillScrollCus',N'Hóa đơn mẫu K80-2',N'lblTieuDeTienphong',N'Tiền sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmRetailBillScrollCus' AND ControlId = 'lblTieuDeKMTienPhong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmRetailBillScrollCus',N'Hóa đơn mẫu K80-2',N'lblTieuDeKMTienPhong',N'KM tiền sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmBillScrollK801' AND ControlId = 'lblTieuDeTienphong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmBillScrollK801',N'Hóa đơn mẫu K80-1',N'lblTieuDeTienphong',N'Tiền sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmBillScrollK801' AND ControlId = 'lblTieuDeKMTienPhong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmBillScrollK801',N'Hóa đơn mẫu K80-1',N'lblTieuDeKMTienPhong',N'KM tiền sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'lblTieudeTiendichvu')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'lblTieudeTiendichvu',N'Tiền dịch vụ :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'lblTieudeTienphong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'lblTieudeTienphong',N'Tiền sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'lblTieudeKMGiohat')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'lblTieudeKMGiohat',N'KM giờ hát :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'lblTieudeKMDichvu')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'lblTieudeKMDichvu',N'Khuyến mãi DV :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'tMnuDel')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'tMnuDel',N'Huỷ sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'mnuRoomInfo')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'mnuRoomInfo',N'Thông tin của sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'mnuAddRoom')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'mnuAddRoom',N'Bổ sung sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmMainTask' AND ControlId = 'lblTieudePhong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmMainTask',N'Giao diện chính',N'lblTieudePhong',N'sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'FrmRetail' AND ControlId = 'dgvRoomMoney')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'FrmRetail',N'Hóa đơn dịch vụ',N'dgvRoomMoney',N'Tiền sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'FrmRetail' AND ControlId = 'lblTieudeTongtienphong')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'FrmRetail',N'Hóa đơn dịch vụ',N'lblTieudeTongtienphong',N'Tổng tiền sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmManager' AND ControlId = 'tsRoom')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmManager',N'Menu giao diện chính',N'tsRoom',N'Danh sách sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmManager' AND ControlId = 'MnuRepTimeUseTotal')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmManager',N'Menu giao diện chính',N'MnuRepTimeUseTotal',N'Báo cáo tổng hợp thời gian sử dụng sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmManager' AND ControlId = 'MnuTimeDetail')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmManager',N'Menu giao diện chính',N'MnuTimeDetail',N'Báo cáo chi tiết thời gian sử dụng sân') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                text = "IF NOT EXISTS (SELECT * FROM TabFormText WHERE FormId = 'frmGeneralConfig' AND ControlId = 'lblObject')";
                text += " BEGIN INSERT INTO TabFormText(FormId,FormDes,ControlId,ControlText1) VALUES(N'frmGeneralConfig',N'Cấu hình chung',N'lblObject',N'sân :') END";
                sqlCommand.CommandText = text;
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            public void setControlText(string FormId, string ControlId, string ControlText2)
            {
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnection);
                    sqlConnection.Open();
                    string commandText = "UPDATE TabFormText SET ControlText2 = @ControlText2 WHERE FormId = @FormId AND ControlId = @ControlId";
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.Parameters.Add("FormId", SqlDbType.NVarChar).Value = FormId;
                    sqlCommand.Parameters.Add("ControlId", SqlDbType.NVarChar).Value = ControlId;
                    sqlCommand.Parameters.Add("ControlText2", SqlDbType.NVarChar).Value = ControlText2;
                    sqlCommand.CommandText = commandText;
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            public string getControlText(string FormId, string ControlId, string oldText)
            {
                string text = oldText;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.strConnection);
                    sqlConnection.Open();
                    string commandText = "SELECT ControlText1, ControlText2 FROM TabFormText WHERE FormId = @FormId AND ControlId = @ControlId";
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.Parameters.Add("FormId", SqlDbType.NVarChar).Value = FormId;
                    sqlCommand.Parameters.Add("ControlId", SqlDbType.NVarChar).Value = ControlId;
                    sqlCommand.CommandText = commandText;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        text = sqlDataReader["ControlText2"].ToString();
                        if (text.Trim() == "")
                        {
                            text = sqlDataReader["ControlText1"].ToString();
                        }
                    }
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    text = oldText;
                }
                return text;
            }
        }
        internal class clsRoom
        {
            private Func objFun = new Func();
            public bool CheckRoom(string roomID)
            {
                bool result = false;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT RoomID FROM [TabRoomRent] WHERE [RoomID] = " + roomID + " AND [Status] = 2", sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = true;
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string getTimeStart(string roomID)
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT TimeStart FROM [TabRoomRent] WHERE [RoomID] = " + roomID + " AND [Status] = 1", sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = sqlDataReader["TimeStart"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public DateTime getTimeStartRoomUsing(string roomID)
            {
                DateTime result = DateTime.Now;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT TimeStart FROM [TabRoomRent] WHERE [RoomID] = " + roomID + " AND [Status] = 1", sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = DateTime.Parse(sqlDataReader["TimeStart"].ToString());
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string gettempRoomName(string roomID)
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT RoomName FROM [TabRoomRent] WHERE [RoomID] = " + roomID + " AND [Status] = 1", sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = sqlDataReader["RoomName"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public float getMoneyRoomUsingChangedRoom(string roomID, ref int Changed, ref DateTime objDatetimeReal, ref float RoomPrice, ref float MoneyRoomChanged)
            {
                float num = 0f;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT [TabRoomRent].[TimeStart] AS TimeStart,[TabRoomRent].[TimeReal]  AS TimeReal,[TabRoomRent].[ChangedRoom]  AS ChangedRoom,[TabRoomRent].[MoneyBeforeChange]  AS MoneyBeforeChange,[TabRoom].[RPrice]  AS RPrice, ISNULL(TimeMinitePause,0) AS TimeMinitePause FROM [TabRoomRent],[TabRoom] WHERE [TabRoomRent].[RoomID]=[TabRoom].[RID] AND [TabRoomRent].[RoomID] = " + roomID + " AND [TabRoomRent].[Status] = 1", sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        if (sqlDataReader["ChangedRoom"].ToString() == "0")
                        {
                            objDatetimeReal = DateTime.Parse(sqlDataReader["TimeStart"].ToString());
                            Changed = 0;
                            int num2 = (int)DateTime.Now.Subtract(objDatetimeReal).TotalMinutes - int.Parse(sqlDataReader["TimeMinitePause"].ToString());
                            num = (float)this.Money3Price(objDatetimeReal, DateTime.Now, roomID, 0);
                            RoomPrice = num / (float)num2;
                        }
                        else
                        {
                            objDatetimeReal = DateTime.Parse(sqlDataReader["TimeReal"].ToString());
                            Changed = 1;
                            MoneyRoomChanged = float.Parse(sqlDataReader["MoneyBeforeChange"].ToString());
                            int num2 = (int)DateTime.Now.Subtract(objDatetimeReal).TotalMinutes - int.Parse(sqlDataReader["TimeMinitePause"].ToString());
                            num = (float)this.Money3Price(objDatetimeReal, DateTime.Now, roomID, 0);
                            RoomPrice = num / (float)num2;
                            num += MoneyRoomChanged;
                        }
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return num;
            }
            public float getMoneyRoomUsingChangedRoom(string roomID, int TypePriceWhenChangedRoom)
            {
                float num = 0f;
                DateTime dateTime = DateTime.Now;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT [TabRoomRent].[TimeStart] AS TimeStart,[TabRoomRent].[TimeReal]  AS TimeReal,[TabRoomRent].[ChangedRoom]  AS ChangedRoom,[TabRoomRent].[MoneyBeforeChange]  AS MoneyBeforeChange,[TabRoom].[RPrice]  AS RPrice, ISNULL(TimeMinitePause,0) as TimeMinitePause FROM [TabRoomRent],[TabRoom] WHERE [TabRoomRent].[RoomID]=[TabRoom].[RID] AND [TabRoomRent].[RoomID] = " + roomID + " AND [TabRoomRent].[Status] = 1", sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        if (sqlDataReader["ChangedRoom"].ToString() == "0" || TypePriceWhenChangedRoom == 0)
                        {
                            dateTime = DateTime.Parse(sqlDataReader["TimeStart"].ToString());
                            int num2 = (int)new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0).Subtract(dateTime).TotalMinutes - int.Parse(sqlDataReader["TimeMinitePause"].ToString());
                            num = (float)this.Money3Price(dateTime, DateTime.Now, roomID, 0);
                        }
                        else
                        {
                            dateTime = DateTime.Parse(sqlDataReader["TimeReal"].ToString());
                            int num2 = (int)new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0).Subtract(dateTime).TotalMinutes - int.Parse(sqlDataReader["TimeMinitePause"].ToString());
                            num = (float)this.Money3Price(dateTime, DateTime.Now, roomID, 0);
                            num += float.Parse(sqlDataReader["MoneyBeforeChange"].ToString());
                        }
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return num;
            }
            public DateTime getTimeEndRoomUsing(string roomID)
            {
                DateTime result = DateTime.Now;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT TimeEnd FROM [TabRoomRent] WHERE [RoomID] = " + roomID + " AND [Status] = 1", sqlConnection);
                sqlConnection.Open();
                try
                {
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        if (sqlDataReader.Read())
                        {
                            result = DateTime.Parse(sqlDataReader["TimeEnd"].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                }
                finally
                {
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                return result;
            }
            public bool getStatus(string roomID, string RepID)
            {
                bool result = false;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand(string.Concat(new string[]
			{
				"SELECT TOP 1 RoomID FROM [TabRoomRent] WHERE [RoomID] = ",
				roomID,
				" AND [Status] = 2 AND [RepID] = '",
				RepID,
				"' "
			}), sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = true;
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string getRepID(string roomID, ref string typeRep)
            {
                string result = "0";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand("SELECT TOP 1 * FROM [TabRoomRent] WHERE [RoomID] = " + roomID + " AND [Status] = 1 ", sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = sqlDataReader["RepID"].ToString();
                        typeRep = sqlDataReader["TypeRep"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string getRepID(string roomID)
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand(string.Concat(new string[]
			{
				"SELECT TOP 1 RepID FROM [TabRoomRent] WHERE ([RoomID] = ",
				roomID,
				" OR CHARINDEX('\"",
				roomID,
				"\"',GroupRoomID) > 0) AND [Status] = 1 "
			}), sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        result = sqlDataReader["RepID"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public string getWhiD(string roomID)
            {
                string result = "0";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT TOP 1 WhID FROM [TabGroupRoom] WHERE GID IN(SELECT TOP 1 GID FROM [TabRoom] WHERE [RID] = " + roomID + ")";
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = sqlDataReader["WhID"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public float getDiscount(string roomID)
            {
                float result = 0f;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.CommandText = "SELECT [Discount] FROM [TabRoom],[TabGroupRoom] WHERE [TabRoom].[GID] = [TabGroupRoom].[Gid] AND [RID] = " + roomID;
                    sqlConnection.Open();
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            result = float.Parse(sqlDataReader["Discount"].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
                return result;
            }
            public string getName(string roomID)
            {
                string result = "0";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT RName FROM [TabRoom] WHERE [RID] = " + roomID;
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = sqlDataReader["RName"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public float getPrice(string roomID)
            {
                float result = 0f;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.CommandText = "SELECT RPrice FROM [TabRoom] WHERE [RID] = " + roomID;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        if (sqlDataReader.Read())
                        {
                            result = float.Parse(sqlDataReader["RPrice"].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    result = 0f;
                }
                return result;
            }
            public float getPrice(string roomID, int AtTime)
            {
                float result = 0f;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    if (AtTime == 0)
                    {
                        sqlCommand.CommandText = "SELECT RPrice as Price FROM [TabRoom] WHERE [RID] = " + roomID;
                    }
                    else
                    {
                        if (AtTime == 1)
                        {
                            sqlCommand.CommandText = "SELECT Price2 as Price  FROM [TabRoom] WHERE [RID] = " + roomID;
                        }
                        else
                        {
                            sqlCommand.CommandText = "SELECT Price3  as Price FROM [TabRoom] WHERE [RID] = " + roomID;
                        }
                    }
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            result = float.Parse(sqlDataReader["Price"].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    result = 0f;
                }
                return result;
            }
            public double Money3Price(DateTime objStart, DateTime objNow, string tempRoomID, int minitePause)
            {
                objStart = new DateTime(objStart.Year, objStart.Month, objStart.Day, objStart.Hour, objStart.Minute, 0);
                objNow = new DateTime(objNow.Year, objNow.Month, objNow.Day, objNow.Hour, objNow.Minute, 0);
                double num = 0.0;
                string str = new DateTime(objNow.Year, objNow.Month, objNow.Day, objNow.Hour, objNow.Minute, 0).ToShortDateString();
                TimeSpan timeSpan = new DateTime(objNow.Year, objNow.Month, objNow.Day, objNow.Hour, objNow.Minute, 0).Subtract(objStart);
                if (minitePause == 0)
                {
                    minitePause = this.getMinitePause(int.Parse(tempRoomID));
                }
                int num2 = (int)timeSpan.TotalMinutes - minitePause;
                if (objStart.ToShortDateString() == objNow.ToShortDateString())
                {
                    if (objStart >= DateTime.Parse(str + " 12:00:00 AM") && objStart <= DateTime.Parse(str + " 08:00:00 AM") && objNow <= DateTime.Parse(str + " 08:00:00 AM"))
                    {
                        num = (double)(this.getPrice(tempRoomID, 0) * (float)num2) / 60.0;
                    }
                    else
                    {
                        if (objStart >= DateTime.Parse(str + " 12:00:00 AM") && objStart <= DateTime.Parse(str + " 08:00:00 AM") && objNow > DateTime.Parse(str + " 08:00:00 AM") && objNow <= DateTime.Parse(str + " 06:00:00 PM"))
                        {
                            int num3 = (int)DateTime.Parse(str + " 08:00:00 AM").Subtract(objStart).TotalMinutes;
                            int num4 = (int)objNow.Subtract(DateTime.Parse(str + " 08:00:00 AM")).TotalMinutes;
                            num = (double)(this.getPrice(tempRoomID, 0) * (float)num3) / 60.0;
                            double num5 = (double)(this.getPrice(tempRoomID, 1) * (float)num4) / 60.0;
                            num += num5;
                        }
                        else
                        {
                            if (objStart > DateTime.Parse(str + " 08:00:00 AM") && objStart <= DateTime.Parse(str + " 06:00:00 PM") && objNow <= DateTime.Parse(str + " 06:00:00 PM"))
                            {
                                num = (double)(this.getPrice(tempRoomID, 1) * (float)num2) / 60.0;
                            }
                            else
                            {
                                if (objStart > DateTime.Parse(str + " 08:00:00 AM") && objStart <= DateTime.Parse(str + " 06:00:00 PM") && objNow > DateTime.Parse(str + " 06:00:00 PM"))
                                {
                                    int num3 = (int)DateTime.Parse(str + " 06:00:00 PM").Subtract(objStart).TotalMinutes;
                                    int num4 = (int)objNow.Subtract(DateTime.Parse(str + " 06:00:00 PM")).TotalMinutes;
                                    num = (double)(this.getPrice(tempRoomID, 1) * (float)num3) / 60.0;
                                    double num5 = (double)(this.getPrice(tempRoomID, 2) * (float)num4) / 60.0;
                                    num += num5;
                                }
                                else
                                {
                                    if (objStart > DateTime.Parse(str + " 06:00:00 PM") && objNow > DateTime.Parse(str + " 06:00:00 PM"))
                                    {
                                        num = (double)(this.getPrice(tempRoomID, 2) * (float)num2) / 60.0;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    int num3 = (int)DateTime.Parse(str + " 12:00:00 AM").Subtract(objStart).TotalMinutes;
                    int num4 = (int)objNow.Subtract(DateTime.Parse(str + " 12:00:00 AM")).TotalMinutes;
                    num = (double)(this.getPrice(tempRoomID, 2) * (float)num3) / 60.0;
                    double num5 = (double)(this.getPrice(tempRoomID, 0) * (float)num4) / 60.0;
                    num += num5;
                }
                return num;
            }
            public string getTimeStart(string roomID, string RepID)
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand(string.Concat(new string[]
			{
				"SELECT TOP 1 TimeStart FROM [TabRoomRent] WHERE [RoomID] = ",
				roomID,
				" AND [Status] = 2 AND [RepID] = '",
				RepID,
				"' "
			}), sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        result = DateTime.Parse(sqlDataReader["TimeStart"].ToString()).ToShortTimeString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public DateTime getTimeStartRoomStop(string roomID, string RepID, int Type)
            {
                DateTime result = DateTime.Now;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                if (Type == 0)
                {
                    sqlCommand.CommandText = string.Concat(new string[]
				{
					"SELECT TimeStart FROM [TabRoomRent] WHERE [RoomID] = ",
					roomID,
					" AND [Status] = 2 AND [RepID] = '",
					RepID,
					"' "
				});
                }
                else
                {
                    sqlCommand.CommandText = "SELECT TimeStart FROM  [TabRoomRentEdit] WHERE [ID] = " + Type;
                }
                sqlConnection.Open();
                try
                {
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            result = DateTime.Parse(sqlDataReader["TimeStart"].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                }
                finally
                {
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                return result;
            }
            public string getTimeEnd(string roomID, string RepID)
            {
                string result = "";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = new SqlCommand(string.Concat(new string[]
			{
				"SELECT TOP 1 TimeEnd FROM [TabRoomRent] WHERE [RoomID] = ",
				roomID,
				" AND [Status] = 2 AND [RepID] = '",
				RepID,
				"' "
			}), sqlConnection);
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = DateTime.Parse(sqlDataReader["TimeEnd"].ToString()).ToShortTimeString();
                    }
                }
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public DateTime getTimeEndRoomStop(string roomID, string RepID, int Type)
            {
                DateTime result = DateTime.Now;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                if (Type == 0)
                {
                    sqlCommand.CommandText = string.Concat(new string[]
				{
					"SELECT TimeEnd FROM [TabRoomRent] WHERE [RoomID] = ",
					roomID,
					" AND [Status] = 2 AND [RepID] = '",
					RepID,
					"' "
				});
                }
                else
                {
                    sqlCommand.CommandText = "SELECT TimeEnd FROM  [TabRoomRentEdit] WHERE [ID] = " + Type;
                }
                sqlConnection.Open();
                try
                {
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    if (sqlDataReader.HasRows)
                    {
                        while (sqlDataReader.Read())
                        {
                            result = DateTime.Parse(sqlDataReader["TimeEnd"].ToString());
                        }
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                }
                catch
                {
                }
                finally
                {
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                return result;
            }
            public string getTimeUse(string roomID, string RepID, int Type)
            {
                string result = "0";
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                if (Type == 0)
                {
                    sqlCommand.CommandText = string.Concat(new string[]
				{
					"SELECT TOP 1 (ISNULL(TimeUse,0)) AS TimeUse FROM [TabRoomRent] WHERE [RoomID] = ",
					roomID,
					" AND [Status] = 2 AND [RepID] = '",
					RepID,
					"' "
				});
                }
                else
                {
                    sqlCommand.CommandText = "SELECT (ISNULL(TimeUse,0)) AS TimeUse FROM  [TabRoomRentEdit] WHERE [ID] = " + Type;
                }
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    if (sqlDataReader.Read())
                    {
                        result = sqlDataReader["TimeUse"].ToString();
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public float getMoneyRoom(string roomID, string RepID, int Type)
            {
                float result = 0f;
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                if (Type == 0)
                {
                    sqlCommand.CommandText = string.Concat(new string[]
				{
					"SELECT TOP 1 RoomMoney FROM [TabRoomRent] WHERE [RoomID] = ",
					roomID,
					" AND [RepID] = '",
					RepID,
					"' "
				});
                }
                else
                {
                    sqlCommand.CommandText = "SELECT TOP 1 RoomMoney FROM [TabRoomRentEdit] WHERE [ID] = " + Type;
                }
                sqlConnection.Open();
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        result = float.Parse(sqlDataReader["RoomMoney"].ToString());
                    }
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                return result;
            }
            public void forWardRoom(string roomIdOld, string roomID, string roomName, float RoomMoneyBeforeChange, string OldRoomName)
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
                sqlConnection.Open();
                roomName = OldRoomName + " - " + roomName;
                sqlCommand.CommandText = string.Concat(new string[]
			{
				"UPDATE [TabRetailsList] SET [cusName] = N'",
				roomName,
				"' WHERE [RetailID] = (SELECT TOP 1 [RepID] FROM [TabRoomRent] WHERE [Status] = 1 AND [RoomID] = ",
				roomIdOld,
				")"
			});
                sqlCommand.ExecuteNonQuery();
                sqlCommand2.CommandText = string.Concat(new object[]
			{
				"UPDATE [TabRoomRent] SET [RoomID] = ",
				roomID,
				", [RoomName] = N'",
				roomName,
				"',[ChangedRoom] = 1,[MoneyBeforeChange]=",
				RoomMoneyBeforeChange,
				",[TimeReal] = @DT  WHERE [Status] = 1 AND [RoomID] = ",
				roomIdOld
			});
                sqlCommand2.Parameters.AddWithValue("@DT", DateTime.Now);
                sqlCommand2.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            public void mixedRoom(string roomIdOld, string roomID)
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand("MixedTable", sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("roomIDRoot", SqlDbType.Int);
                sqlCommand.Parameters.Add("roomIDChild", SqlDbType.Int);
                sqlCommand.Parameters.Add("roomAdd", SqlDbType.NVarChar, 200);
                sqlCommand.Parameters["roomIDRoot"].Value = int.Parse(roomIdOld);
                sqlCommand.Parameters["roomIDChild"].Value = int.Parse(roomID);
                sqlCommand.Parameters["roomAdd"].Value = "\"" + roomID + "\",";
                sqlCommand.ExecuteNonQuery();
                string retailID = "";
                string str = "";
                SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
                sqlCommand2.CommandText = "SELECT [RepID] FROM [TabRoomRent] WHERE [RoomID] = '" + roomIdOld + "' AND [Status] = 1";
                SqlDataReader sqlDataReader = sqlCommand2.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    retailID = sqlDataReader["RepID"].ToString();
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                SqlCommand sqlCommand3 = sqlConnection.CreateCommand();
                sqlCommand3.CommandText = "SELECT [RepID] FROM [TabRoomRent] WHERE [RoomID] = '" + roomID + "' AND [Status] = 1";
                SqlDataReader sqlDataReader2 = sqlCommand3.ExecuteReader();
                while (sqlDataReader2.Read())
                {
                    str = sqlDataReader2["RepID"].ToString();
                }
                sqlDataReader2.Close();
                sqlDataReader2.Dispose();
                SqlCommand sqlCommand4 = sqlConnection.CreateCommand();
                sqlCommand4.CommandText = "SELECT * FROM [TabRetailsLink] WHERE [RetailID] = '" + str + "'";
                SqlDataReader sqlDataReader3 = sqlCommand4.ExecuteReader();
                while (sqlDataReader3.Read())
                {
                    this.ActMixed(retailID, int.Parse(sqlDataReader3["ProID"].ToString()), sqlDataReader3["ProName"].ToString(), sqlDataReader3["PDonViTinh"].ToString(), int.Parse(sqlDataReader3["Number"].ToString()), float.Parse(sqlDataReader3["PriceBase"].ToString()), sqlDataReader3["Price"].ToString(), "0", float.Parse(sqlDataReader3["TotalMoney"].ToString()));
                }
                sqlDataReader3.Close();
                sqlDataReader3.Dispose();
                SqlCommand sqlCommand5 = new SqlCommand("DELETE FROM [TabRetailsLink] WHERE [RetailID] = '" + str + "'", sqlConnection);
                sqlCommand5.ExecuteNonQuery();
                SqlCommand sqlCommand6 = new SqlCommand("DELETE FROM [TabRetailsList] WHERE [RetailID] = '" + str + "'", sqlConnection);
                sqlCommand6.ExecuteNonQuery();
                SqlCommand sqlCommand7 = new SqlCommand("DELETE FROM [TabRoomRent] WHERE [Status] = 1 AND [RoomID] = " + roomID, sqlConnection);
                sqlCommand7.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            private void ActMixed(string RetailID, int ProID, string ProName, string PDonViTinh, int Number, float PriceBase, string Price, string Tax, float TotalMoney)
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand("MixedOnTabRetailsLink", sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@RetailID", SqlDbType.VarChar);
                sqlCommand.Parameters.Add("@ProID", SqlDbType.Int);
                sqlCommand.Parameters.Add("@ProName", SqlDbType.NVarChar, 300);
                sqlCommand.Parameters.Add("@PDonViTinh", SqlDbType.NVarChar, 300);
                sqlCommand.Parameters.Add("@Tax", SqlDbType.Float);
                sqlCommand.Parameters.Add("@Price", SqlDbType.Float);
                sqlCommand.Parameters.Add("@PriceBase", SqlDbType.Float);
                sqlCommand.Parameters.Add("@Number", SqlDbType.Int);
                sqlCommand.Parameters.Add("@TotalMoney", SqlDbType.Float);
                sqlCommand.Parameters["@RetailID"].Value = RetailID;
                sqlCommand.Parameters["@ProID"].Value = ProID;
                sqlCommand.Parameters["@ProName"].Value = ProName;
                sqlCommand.Parameters["@PDonViTinh"].Value = PDonViTinh;
                sqlCommand.Parameters["@Number"].Value = Number;
                sqlCommand.Parameters["@PriceBase"].Value = PriceBase;
                sqlCommand.Parameters["@Price"].Value = Price;
                sqlCommand.Parameters["@Tax"].Value = "0";
                sqlCommand.Parameters["@TotalMoney"].Value = TotalMoney;
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            public void updateGroupRoomID(string roomId, string listRoomID)
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlConnection.Open();
                sqlCommand.CommandText = "UPDATE [TabRoomRent] SET [GroupRoomID] = '" + listRoomID + "' WHERE [Status] = 1 AND [RoomID] = " + roomId;
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            public void setPause(string billId, int roomId, DateTime TimePause, DateTime TimeResume)
            {
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string text = "IF NOT EXISTS (SELECT * FROM tblPause WHERE RoomId = @RoomId AND Status  = 0)";
                    text += " BEGIN INSERT INTO tblPause(TimePause,RoomId,BillId,Status,Closed) VALUES(@TimePause,@RoomId,@BillId,0,0) END";
                    text += " ELSE BEGIN UPDATE tblPause SET TimeResume = @TimeResume, BillId = @BillId, Status = 1 WHERE RoomId = @RoomId AND Status = 0 END";
                    sqlCommand.CommandText = text;
                    sqlCommand.Parameters.Add("BillId", SqlDbType.NVarChar).Value = billId;
                    sqlCommand.Parameters.Add("RoomId", SqlDbType.Int).Value = roomId;
                    sqlCommand.Parameters.Add("TimePause", SqlDbType.DateTime).Value = new DateTime(TimePause.Year, TimePause.Month, TimePause.Day, TimePause.Hour, TimePause.Minute, 0);
                    sqlCommand.Parameters.Add("TimeResume", SqlDbType.DateTime).Value = new DateTime(TimeResume.Year, TimeResume.Month, TimeResume.Day, TimeResume.Hour, TimeResume.Minute, 0);
                    sqlCommand.ExecuteNonQuery();
                    text = "UPDATE TabRoomRent SET TimeMinitePause = (SELECT ISNULL(SUM(datediff(mi,TimePause,TimeResume)),0) as SumMinite FROM tblPause WHERE RoomId = @RoomId AND Status = 1 AND Closed = 0) WHERE RoomId = @RoomId AND Status = 1";
                    sqlCommand.CommandText = text;
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
            }
            public bool checkRoomPause(int roomId)
            {
                bool result = false;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "SELECT * FROM tblPause WHERE RoomId = @RoomId AND TimePause IS NOT NULL AND TimeResume IS NULL";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("RoomId", SqlDbType.Int).Value = roomId;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = true;
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    result = false;
                }
                return result;
            }
            public void finishAllPause(int roomId)
            {
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "UPDATE tblPause SET Closed = 1 WHERE RoomId = @RoomId AND Closed = 0";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("RoomId", SqlDbType.Int).Value = roomId;
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
            }
            public void setBillIdPause(int roomId, string billId)
            {
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "UPDATE tblPause SET BillId = @BillId WHERE RoomId = @RoomId AND BillId = ''";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("BillId", SqlDbType.NVarChar).Value = billId;
                    sqlCommand.Parameters.Add("RoomId", SqlDbType.Int).Value = roomId;
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
            }
            public int getMinitePause(int roomId)
            {
                int result = 0;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "SELECT ISNULL(SUM(datediff(mi,TimePause,TimeResume)),0) as SumMinite FROM tblPause WHERE RoomId = @RoomId AND BillId = ''";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("RoomId", SqlDbType.Int).Value = roomId;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = int.Parse(sqlDataReader["SumMinite"].ToString());
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    result = 0;
                }
                return result;
            }
            public int getMinitePause(string billId)
            {
                int result = 0;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "SELECT ISNULL(SUM(datediff(mi,TimePause,TimeResume)),0) as SumMinite FROM tblPause WHERE billId = @billId";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("billId", SqlDbType.NVarChar).Value = billId;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = int.Parse(sqlDataReader["SumMinite"].ToString());
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    result = 0;
                }
                return result;
            }
            public int getMinitePauseByBillId(string billId)
            {
                int result = 0;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "SELECT ISNULL(SUM(TimeMinitePause),0) as SumMinite FROM TabRoomRent WHERE RepID = @RepID";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("RepID", SqlDbType.VarChar).Value = billId;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = int.Parse(sqlDataReader["SumMinite"].ToString());
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    result = 0;
                }
                return result;
            }
            public void delPause(int roomId)
            {
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "DELETE tblPause WHERE RoomId = @RoomId AND BillId = ''";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("RoomId", SqlDbType.Int).Value = roomId;
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
            }
            public void setEmpId(string EmpId, string BillId)
            {
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "UPDATE TabRoomRent SET EmpId = @EmpId WHERE RepID = @RepID";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("RepID", SqlDbType.VarChar).Value = BillId;
                    sqlCommand.Parameters.Add("EmpId", SqlDbType.NVarChar).Value = EmpId;
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
            }
            public string getEmp(string billId)
            {
                string result = "";
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    string commandText = "SELECT EmpName FROM TabEmployee WHERE EmpID = (SELECT TOP 1 EmpId FROM TabRoomRent WHERE RepID = @RepID)";
                    sqlCommand.CommandText = commandText;
                    sqlCommand.Parameters.Add("RepID", SqlDbType.VarChar).Value = billId;
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = sqlDataReader["EmpName"].ToString();
                    }
                    sqlDataReader.Close();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                    result = "";
                }
                return result;
            }
        }
        internal class Regis
        {
            private Func objFunc = new Func();
            public string GetSerial()
            {
                return ConfigurationSettings.AppSettings["License"].ToString();
            }
            public bool CheckForRes()
            {
                bool result = false;
                string cDKey = this.GetCDKey(this.InsertInfo("Win32_Processor"));
                if (cDKey.ToUpper() == this.GetSerial().ToUpper())
                {
                    result = true;
                }
                return result;
            }
            private string GetStrConnectionString()
            {
                string result = "";
                try
                {
                    StreamReader streamReader = File.OpenText("Config.ini");
                    int num = 0;
                    string text;
                    while ((text = streamReader.ReadLine()) != null)
                    {
                        num++;
                        if (num == 1)
                        {
                            int num2 = num;
                            if (num2 != 1)
                            {
                                num = 0;
                            }
                            else
                            {
                                result = text;
                            }
                        }
                    }
                    streamReader.Close();
                }
                catch
                {
                    result = "";
                }
                return result;
            }
            public int GetCountBill1()
            {
                int result = 0;
                try
                {
                    SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
                    sqlConnection.Open();
                    SqlCommand sqlCommand = sqlConnection.CreateCommand();
                    sqlCommand.CommandText = "SELECT COUNT(*) AS TOTALITEM FROM [TabReceipt]";
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    while (sqlDataReader.Read())
                    {
                        result = int.Parse(sqlDataReader["TOTALITEM"].ToString());
                    }
                    sqlDataReader.Close();
                    sqlDataReader.Dispose();
                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
                catch
                {
                }
                return result;
            }
            public string GetCDKey(string Source)
            {
                string text = "";
                string[] array = new string[]
			{
				"M",
				"I",
				"N",
				"H",
				"Q",
				"U",
				"A",
				"N",
				"G",
				"P",
				"L",
				"K",
				"J",
				"H",
				"G",
				"F",
				"D",
				"S",
				"A",
				"Z",
				"T",
				"V",
				"S",
				"G",
				"A",
				"S"
			};
                string[] array2 = new string[]
			{
				"M",
				"I",
				"N",
				"H",
				"Q",
				"U",
				"A",
				"N",
				"G",
				"P",
				"O",
				"H",
				"L",
				"K",
				"N",
				"A",
				"S",
				"D",
				"F",
				"C",
				"T",
				"V",
				"S",
				"G",
				"A",
				"S"
			};
                if (Source != "")
                {
                    text = this.CryptographyMD5(Source);
                    char[] array3 = text.ToCharArray(0, text.Trim().Length);
                    for (int i = 0; i < array3.Length; i++)
                    {
                        if (i % 2 == 1)
                        {
                            text += array3[i];
                        }
                    }
                    char[] array4 = text.Trim().ToCharArray(0, text.Trim().Length);
                    text = "";
                    for (int j = 0; j < 20; j++)
                    {
                        if (j % 2 == 1)
                        {
                            text += array[int.Parse(array3[j].ToString())];
                        }
                        else
                        {
                            text += array2[int.Parse(array3[j].ToString())];
                        }
                    }
                }
                return text;
            }
            public string InsertInfo(string Key)
            {
                string result = "";
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("select * from " + Key);
                try
                {
                    using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ManagementObject managementObject = (ManagementObject)enumerator.Current;
                            foreach (PropertyData current in managementObject.Properties)
                            {
                                if (current.Name.ToUpper() == "PROCESSORID")
                                {
                                    if (current.Value != null && current.Value.ToString() != "")
                                    {
                                        string text = current.Value.GetType().ToString();
                                        if (text == null)
                                        {
                                            goto IL_180;
                                        }
                                        if (!(text == "System.String[]"))
                                        {
                                            if (!(text == "System.UInt16[]"))
                                            {
                                                goto IL_180;
                                            }
                                            ushort[] array = (ushort[])current.Value;
                                            string text2 = "";
                                            ushort[] array2 = array;
                                            for (int i = 0; i < array2.Length; i++)
                                            {
                                                ushort num = array2[i];
                                                text2 = text2 + num.ToString() + " ";
                                            }
                                            result = text2;
                                        }
                                        else
                                        {
                                            string[] array3 = (string[])current.Value;
                                            string text3 = "";
                                            string[] array4 = array3;
                                            for (int i = 0; i < array4.Length; i++)
                                            {
                                                string str = array4[i];
                                                text3 = text3 + str + " ";
                                            }
                                            result = text3;
                                        }
                                        continue;
                                    IL_180:
                                        result = current.Value.ToString();
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("can't get data because of the followeing error \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                return result;
            }
            public string CryptographyMD5(string source)
            {
                string text = "";
                try
                {
                    MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
                    byte[] bytes = Encoding.UTF8.GetBytes(source);
                    byte[] array = mD5CryptoServiceProvider.ComputeHash(bytes);
                    byte[] array2 = array;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        byte b = array2[i];
                        text += int.Parse(b.ToString(), NumberStyles.HexNumber).ToString();
                    }
                }
                catch
                {
                }
                return text;
            }
        }
        public class ItemCombobox
        {
            public string Name;
            public string Value;
            public ItemCombobox(string name, string value)
            {
                this.Name = name;
                this.Value = value;
            }
            public override string ToString()
            {
                return this.Name;
            }
        }
        private int CheckGroupIndex(string GidToCheck)
        {
            int result;
            for (int i = 0; i < this.listView1.Groups.Count; i++)
            {
                if (this.listView1.Groups[i].Name.ToUpper() == GidToCheck.ToUpper())
                {
                    result = i;
                    return result;
                }
            }
            result = 0;
            return result;
        }

        public delegate void doUpdate();
        private DataGridViewCellStyle objRowColor = new DataGridViewCellStyle();
        private clsRoom objRoom = new clsRoom();
        private XmlDocument xmlDoc = new XmlDocument();
        private clsFormText objFormText = new clsFormText();
        private DataTable objTable;
        private int lien = 1;
        private int calByPercent = 0;
        private bool endpage = false;
        private int Index = 0;
        private int PageNumber = 0;
        private int productIndex = 0;
        private float RoomPrice = 0f;
        private string currRoomID = "0";
        private string TimeStart = "";
        private string TimeEnd = "";
        private string TimeUse = "";
        private string[] RoomID = new string[100];
        public string[] RoomName = new string[100];
        private bool CanEdit = false;
        private string[] ProOrder = new string[]
		{
			""
		};
        private int Numbill = 1;
        public string UserName;
        public string Permission;
        public string Password;
        public string FullName;
        public string objTime = "";
        public int timeStop = 0;
        private float moneyRoom = 0f;
        private clsRoom objR = new clsRoom();
        private Func objFunc = new Func();
        public bool Register = false;
        public bool tempLoad;
        private float discount = 0f;
        private string CurrRoomName = "";
        private int TypePriceWhenChangeRoom = 0;
        private string ComName = "";
        private string ComPhone = "";
        private string ComAddress = "";
        private bool LoadingFlag = false;
        private int CurrentRoomChanged = 0;
        private float MoneyRoomChanged = 0f;
        private DateTime RoomStartDateTimeReal = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
        private DateTime CurrRoomTimeStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
        private DateTime RoomStartRealNew = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
        private int PrintType = 5;
        public string Permisstion = "";

        public frmBanHang()
        {
            InitializeComponent();
        }

        private void ReFresh()
        {
            this.listView1.SetExStyles();
            this.listView1.Items.Clear();
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = "SELECT *, Replace((RName +'-'+ ISNULL((SELECT TOP 1 CAST(ISNULL(datepart(Hour,TimeStart),'') as varchar)+':'+CAST(ISNULL(datepart(Minute,TimeStart),'') as varchar) FROM TabRoomRent WHERE RoomID = a.Rid AND Status = 1),'+')),'-+','') as RName1 FROM [TabRoom] a ORDER BY [Poss] ASC";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            int num = 0;
            while (sqlDataReader.Read())
            {
                this.RoomID[num] = sqlDataReader["RID"].ToString();
                this.RoomName[num] = sqlDataReader["RName"].ToString();
                this.listView1.Items.Add(sqlDataReader["RName1"].ToString().Trim().ToUpper(), 1);
                this.listView1.Items[num].Name = sqlDataReader["RID"].ToString();
                int index = this.CheckGroupIndex(sqlDataReader["GID"].ToString());
                this.listView1.Items[num].Group = this.listView1.Groups[index];
                num++;
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            this.listView1.Update();
            this.listView2.Items.Clear();
            SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
            sqlCommand2.CommandText = "SELECT * FROM [TabRoomRent] WHERE [Status] = 1 ";
            SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
            this.Index = 0;
            while (sqlDataReader2.Read())
            {
                this.listView2.Items.Add(sqlDataReader2["RoomID"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader2["RoomName"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(DateTime.Parse(sqlDataReader2["TimeStart"].ToString()).ToString("HH:mm"));
                this.listView2.Items[this.Index].SubItems.Add(int.Parse(sqlDataReader2["TimeUse"].ToString()).ToString());
                try
                {
                    this.listView2.Items[this.Index].SubItems.Add(DateTime.Parse(sqlDataReader2["TimeEnd"].ToString()).ToString("HH:mm"));
                }
                catch
                {
                    this.listView2.Items[this.Index].SubItems.Add("");
                }
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader2["RoomMoney"].ToString())));
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader2["ServiceMoney"].ToString())));
                float num2 = float.Parse(sqlDataReader2["RoomMoney"].ToString()) + float.Parse(sqlDataReader2["ServiceMoney"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", num2));
                this.listView2.Items[this.Index].SubItems.Add("");
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader2["GroupRoomID"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader2["ChangedRoom"].ToString());
                this.Index++;
            }
            sqlDataReader2.Close();
            sqlDataReader2.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
            this.listView2.Update();
            this.updateListView1Status();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.CheckItemInList(this.RoomID[i].ToString()))
                {
                    int itemIndex = this.getItemIndex(this.RoomID[i].ToString());
                }
                else
                {
                    this.listView1.Items[i].ImageIndex = 1;
                }
            }
            this.getNumVip();
        }
        
        private void AddGroup()
        {
            this.listView1.Groups.Clear();
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = "SELECT Gid,GName,Discount FROM [TabGroupRoom] WHERE [Gid] IN (SELECT DISTINCT GID FROM TabRoom) ORDER BY [Poss] ASC";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                ListViewGroup listViewGroup = new ListViewGroup();
                listViewGroup.Header = sqlDataReader["GName"].ToString().ToUpper();
                listViewGroup.Name = sqlDataReader["Gid"].ToString();
                listViewGroup.HeaderAlignment = HorizontalAlignment.Center;
                listViewGroup.Tag = string.Format("{0:###,0}", float.Parse(sqlDataReader["Discount"].ToString()));
                this.listView1.Groups.Add(listViewGroup);
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private void updateListView1Status()
        {
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.CheckItemInList(this.RoomID[i].ToString()))
                {
                    if (this.objRoom.checkRoomPause(int.Parse(this.RoomID[i].ToString())))
                    {
                        this.listView1.Items[i].ImageIndex = 2;
                    }
                    else
                    {
                        this.listView1.Items[i].ImageIndex = 0;
                    }
                }
                else
                {
                    this.listView1.Items[i].ImageIndex = 1;
                }
                string parentName = this.getParentName(this.listView1.Items[i].Name);
                if (parentName != "")
                {
                    this.listView1.Items[i].Text = this.listView1.Items[i].Text + "\r\n[ " + parentName + " ]";
                }
            }
        }
        private void CreateTable()
        {
            this.objTable = new DataTable();
            DataColumn dataColumn = new DataColumn();
            dataColumn.ColumnName = "Name";
            dataColumn.DataType = typeof(string);
            DataColumn dataColumn2 = new DataColumn();
            dataColumn2.ColumnName = "DVT";
            dataColumn2.DataType = typeof(string);
            DataColumn dataColumn3 = new DataColumn();
            dataColumn3.ColumnName = "Number";
            dataColumn3.DataType = typeof(int);
            DataColumn dataColumn4 = new DataColumn();
            dataColumn4.ColumnName = "Price";
            dataColumn4.DataType = typeof(float);
            DataColumn dataColumn5 = new DataColumn();
            dataColumn5.ColumnName = "TotalMoney";
            dataColumn5.DataType = typeof(float);
            this.objTable.Columns.Add(dataColumn);
            this.objTable.Columns.Add(dataColumn2);
            this.objTable.Columns.Add(dataColumn3);
            this.objTable.Columns.Add(dataColumn4);
            this.objTable.Columns.Add(dataColumn5);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.lblTieudeTiendichvu.Text = this.objFormText.getControlText("frmMainTask", "lblTieudeTiendichvu", this.lblTieudeTiendichvu.Text);
            this.lblTieudeTienphong.Text = this.objFormText.getControlText("frmMainTask", "lblTieudeTienphong", this.lblTieudeTienphong.Text);
            this.lblTieudeKMGiohat.Text = this.objFormText.getControlText("frmMainTask", "lblTieudeKMGiohat", this.lblTieudeKMGiohat.Text);
            this.lblTieudeKMDichvu.Text = this.objFormText.getControlText("frmMainTask", "lblTieudeKMDichvu", this.lblTieudeKMDichvu.Text);
            this.tMnuDel.Text = this.objFormText.getControlText("frmMainTask", "tMnuDel", this.tMnuDel.Text);
            this.mnuRoomInfo.Text = this.objFormText.getControlText("frmMainTask", "mnuRoomInfo", this.mnuRoomInfo.Text);
            this.mnuAddRoom.Text = this.objFormText.getControlText("frmMainTask", "mnuAddRoom", this.mnuAddRoom.Text);
            this.btnVipCounter.Enabled = clsGeneral.CusVIP;
            this.btnVipCounter.Visible = clsGeneral.CusVIP;
            this.imageList1.ImageSize = new Size(int.Parse(clsGeneral.iconWidth), int.Parse(clsGeneral.iconHeight));
            if (this.objFunc.getShowItemByGroup() == 1)
            {
                this.listView1.ShowGroups = true;
            }
            else
            {
                this.listView1.ShowGroups = false;
            }
            this.getCalByPercent();
            this.objRowColor.BackColor = SystemColors.Control;
            this.LoadDataImg();
            try
            {
                this.Numbill = int.Parse(ConfigurationSettings.AppSettings["Number"].ToString());
                this.PrintType = int.Parse(ConfigurationSettings.AppSettings["Print"].ToString());
            }
            catch
            {
                this.Numbill = 1;
                this.PrintType = 5;
            }
            this.CreateTable();
            this.objTime = this.objFunc.getPointDate();
            this.getCompanyInfor();
            this.AddGroup();
            Regis regis = new Regis();
            this.CanEdit = true;
            this.btnEditTime.Visible = true;
            this.btnSaveEditTime.Visible = true;
            this.TypePriceWhenChangeRoom = this.objFunc.GetConfigPriceWhenChange();
            this.objFunc.LoadComboBox("SELECT WareHouse_ID,WareHouse_Name FROM [TabWareHouse]", this.cbBWareHouse, "WareHouse_ID", "WareHouse_Name");
            this.LoadProvider();
            this.objFunc.LoadComboBox("SELECT UnitID,UnitName FROM [TabUnitProduct]", this.cbbUnit, "UnitID", "UnitName");
            this.searchProduct("");
            this.ReFresh();
            this.CreateTable();
            this.getOtherMoney();
        }
        private void txtEnter(object sender, EventArgs e)
        {
        }
        private void txtLeave(object sender, EventArgs e)
        {
        }
        private void loadInformation(string _roomID, int TempTimeUse)
        {
            this.txtRetailID.Text = this.objR.getRepID(_roomID);
            double num;
            if (this.TypePriceWhenChangeRoom == 0)
            {
                num = this.objR.Money3Price(this.TPTimeStart.Value, DateTime.Now, _roomID, this.objRoom.getMinitePause(int.Parse(_roomID)));
                this.RoomPrice = (float)(num / 60.0);
                this.CurrentRoomChanged = 0;
            }
            else
            {
                num = (double)this.objR.getMoneyRoomUsingChangedRoom(_roomID, ref this.CurrentRoomChanged, ref this.RoomStartDateTimeReal, ref this.RoomPrice, ref this.MoneyRoomChanged);
            }
            this.txtMoneyRoom.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(num, clsGeneral.roundValue));
            this.cbBWareHouse.SelectedValue = this.objR.getWhiD(_roomID);
            this.txtCusName.Text = this.objR.gettempRoomName(_roomID);
            if (this.txtRetailID.Text != "")
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT * FROM [TabRetailsList] WHERE [RetailID] = '" + this.txtRetailID.Text + "' ";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    this.cbBWareHouse.SelectedValue = sqlDataReader["WHID"].ToString();
                    this.objFunc.SelectValueCombobox(this.cbbCustomer, sqlDataReader["PartnerID"].ToString());
                    this.txtOrderNote.Text = sqlDataReader["Note"].ToString();
                    this.txtCusName.Text = sqlDataReader["CusName"].ToString();
                    try
                    {
                        this.txtKmGH.Text = sqlDataReader["PerPromoteTime"].ToString();
                    }
                    catch
                    {
                        this.txtKmGH.Text = "0";
                    }
                    this.txtPerPromote.Text = sqlDataReader["PerPromote"].ToString();
                    this.txtKmGH.Text = string.Format("{0:###,0}", double.Parse(sqlDataReader["PerPromoteTime"].ToString()));
                    if (this.calByPercent == 0)
                    {
                        this.txtTienKMGH.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(double.Parse(sqlDataReader["PromoteTime"].ToString()), clsGeneral.roundValue));
                    }
                    this.txtPerPromote.Text = string.Format("{0:###,0}", double.Parse(sqlDataReader["PerPromote"].ToString()));
                    if (this.calByPercent == 0)
                    {
                        this.txtMoneyPromote.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(double.Parse(sqlDataReader["Promote"].ToString()), clsGeneral.roundValue));
                    }
                    this.txtVAT.Text = sqlDataReader["VAT"].ToString();
                    if (sqlDataReader["PartnerID"].ToString() != "0")
                    {
                        this.txtTotalPay.ReadOnly = false;
                    }
                    else
                    {
                        this.txtTotalPay.ReadOnly = true;
                    }
                    this.calTotalMoney();
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
                sqlConnection.Close();
                sqlConnection.Dispose();
                this.getOrderLink();
            }
            else
            {
                this.lvProduct.Items.Clear();
            }
        }
        private void loadService(int tempCurrIndex, string tempCurrRoomID, string tempCurrRoomName, int tempTimeUse)
        {
            try
            {
                this.currRoomID = tempCurrRoomID;
                if (!this.isParentItem1(tempCurrRoomID))
                {
                    tempCurrRoomID = this.getParentMixed(tempCurrRoomID);
                }
                int itemIndex = this.getItemIndex(tempCurrRoomID);
                if (itemIndex != 101)
                {
                    this.loadInformation(tempCurrRoomID, tempTimeUse);
                    if (this.CmdAddRows.Enabled)
                    {
                        this.lvProduct.ContextMenuStrip = this.contextMenuStrip2;
                    }
                    else
                    {
                        this.lvProduct.ContextMenu = null;
                    }
                }
                else
                {
                    int num = this.checkMixed(tempCurrRoomID);
                    if (num != -1)
                    {
                        this.loadInformation(tempCurrRoomID, tempTimeUse);
                        if (this.CmdAddRows.Enabled)
                        {
                            this.lvProduct.ContextMenuStrip = this.contextMenuStrip2;
                        }
                        else
                        {
                            this.lvProduct.ContextMenu = null;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Chưa sân nào được chọn để cập nhật dịch vụ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            catch
            {
            }
        }
        private void getOrderLink()
        {
            this.lvProduct.Items.Clear();
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = "SELECT * FROM [TabRetailsLink] WHERE [RetailID] = '" + this.txtRetailID.Text + "' ORDER BY [OrderNumber]";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            this.Index = 0;
            while (sqlDataReader.Read())
            {
                this.lvProduct.Items.Add(sqlDataReader["ProID"].ToString());
                this.lvProduct.Items[this.Index].SubItems.Add(sqlDataReader["ProName"].ToString());
                if (sqlDataReader["UnitName"].ToString().Trim() != "")
                {
                    this.lvProduct.Items[this.Index].SubItems.Add(sqlDataReader["UnitName"].ToString());
                }
                else
                {
                    this.lvProduct.Items[this.Index].SubItems.Add(this.objFunc.getValue("TabUnitProduct", "UnitName", "UnitID", sqlDataReader["PDonViTinh"].ToString()));
                }
                this.lvProduct.Items[this.Index].SubItems.Add("0");
                this.lvProduct.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", int.Parse(sqlDataReader["Number"].ToString())));
                this.lvProduct.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", int.Parse(sqlDataReader["Number"].ToString())));
                this.lvProduct.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader["Price"].ToString())));
                this.lvProduct.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader["TotalMoney"].ToString())));
                this.lvProduct.Items[this.Index].SubItems.Add(sqlDataReader["PDonViTinh"].ToString());
                this.Index++;
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
            this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
        }
        private bool CheckForm(string FormName)
        {
            bool result = false;
            Form[] mdiChildren = base.ParentForm.MdiChildren;
            for (int i = 0; i < mdiChildren.Length; i++)
            {
                Form form = mdiChildren[i];
                if (FormName == form.Name.ToString())
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
        private void FocusWhenStart(int tmpIndex)
        {
            try
            {
                this.lblCurrIndex.Text = tmpIndex.ToString();
                string[] array = this.listView1.Items[tmpIndex].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[tmpIndex].ToString();
                this.discount = float.Parse(this.listView1.Items[tmpIndex].Group.Tag.ToString());
                this.CurrentRoomChanged = 0;
                this.MoneyRoomChanged = 0f;
                this.RoomStartDateTimeReal = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
                this.TPTimeStart.Enabled = false;
                this.SetRepDetailsNew();
                int itemIndex = this.getItemIndex(this.currRoomID);
                bool flag = this.CheckItemInList(this.currRoomID);
                if (flag)
                {
                    this.cmdStart.Enabled = false;
                    this.btnDel.Enabled = true;
                    this.TPTimeStart.Value = this.objR.getTimeStartRoomUsing(this.currRoomID);
                    this.CurrRoomTimeStart = this.TPTimeStart.Value;
                    int tempTimeUse = (int)DateTime.Now.Subtract(this.TPTimeStart.Value).TotalMinutes - this.objRoom.getMinitePause(int.Parse(this.currRoomID));
                    this.txtTimeUse.Text = tempTimeUse.ToString();
                    this.CmdAddRows.Enabled = true;
                    this.btnEditTime.Enabled = true;
                    this.btnSaveEditTime.Enabled = false;
                    this.loadService(tmpIndex, this.currRoomID, this.lblRoomName.Text.Trim(), tempTimeUse);
                }
                else
                {
                    this.TPTimeStart.Value = DateTime.Now;
                    this.CurrRoomTimeStart = this.TPTimeStart.Value;
                    this.txtTimeUse.Text = "0";
                    this.cmdStart.Enabled = true;
                    this.btnDel.Enabled = false;
                    this.CmdAddRows.Enabled = false;
                    this.btnEditTime.Enabled = false;
                    this.btnSaveEditTime.Enabled = false;
                }
            }
            catch
            {
                this.currRoomID = "0";
            }
        }
        private void cmdStart_Click(object sender, EventArgs e)
        {
            this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
            int tmpIndex = int.Parse(this.lblCurrIndex.Text);
            this.ListView2Update();
            this.ReFresh();
            this.FocusWhenStart(tmpIndex);
            this.getOtherMoney();
            this.SaveLog(this.lblRoomName.Text, 1);
            this.tsMnuPause.Visible = clsGeneral.Pause;
            this.tsMnuPause.Enabled = clsGeneral.Pause;
        }
        private void SaveLog(string tmpRoom, int tmptype)
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand("InsertIntoTabLog", sqlConnection);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add("@EmpID", SqlDbType.VarChar, 50);
            sqlCommand.Parameters.Add("@RoomName", SqlDbType.NVarChar, 200);
            sqlCommand.Parameters.Add("@TimeLog", SqlDbType.DateTime);
            sqlCommand.Parameters.Add("@Note", SqlDbType.NVarChar, 300);
            sqlCommand.Parameters["@EmpID"].Value = this.UserName;
            sqlCommand.Parameters["@RoomName"].Value = this.lblRoomName.Text;
            if (tmptype == 1)
            {
                sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
                sqlCommand.Parameters["@Note"].Value = "Bắt đầu sử dụng sân " + tmpRoom;
            }
            else
            {
                if (tmptype == 2)
                {
                    sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
                    sqlCommand.Parameters["@Note"].Value = "Ngừng sử dụng sân " + tmpRoom;
                }
                else
                {
                    if (tmptype == 3)
                    {
                        sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
                        sqlCommand.Parameters["@Note"].Value = "Hủy sân " + tmpRoom;
                    }
                }
            }
            if (tmptype == 4)
            {
                sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
                sqlCommand.Parameters["@Note"].Value = "Sửa thời gian vào cho sân " + tmpRoom;
            }
            else
            {
                if (tmptype == 5)
                {
                    sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
                    sqlCommand.Parameters["@Note"].Value = "Thanh toán và in hóa đơn sân " + tmpRoom;
                }
                else
                {
                    if (tmptype == 6)
                    {
                        sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
                        sqlCommand.Parameters["@Note"].Value = "In hóa đơn cho sân " + tmpRoom;
                    }
                }
            }
            sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private void SaveLogMove(string tmpRoom, string tmpRoomEnd)
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand("InsertIntoTabLog", sqlConnection);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add("@EmpID", SqlDbType.VarChar, 50);
            sqlCommand.Parameters.Add("@RoomName", SqlDbType.NVarChar, 200);
            sqlCommand.Parameters.Add("@TimeLog", SqlDbType.DateTime);
            sqlCommand.Parameters.Add("@Note", SqlDbType.NVarChar, 300);
            sqlCommand.Parameters["@EmpID"].Value = this.UserName;
            sqlCommand.Parameters["@RoomName"].Value = tmpRoom;
            sqlCommand.Parameters["@TimeLog"].Value = DateTime.Now;
            sqlCommand.Parameters["@Note"].Value = "Chuyển " + tmpRoom + " sang " + tmpRoomEnd;
            sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private bool CheckItemInList(string ItemID)
        {
            bool result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[0].Text == ItemID || this.listView2.Items[i].SubItems[9].Text.Contains("\"" + ItemID + "\""))
                {
                    result = true;
                    return result;
                }
            }
            result = false;
            return result;
        }
        private int CheckItemInList1(string ItemID)
        {
            int result;
            for (int i = 0; i < this.lvProduct.Items.Count; i++)
            {
                if (this.lvProduct.Items[i].SubItems[0].Text == ItemID)
                {
                    result = i;
                    return result;
                }
            }
            result = -1;
            return result;
        }
        private int getItemIndex(string ItemID)
        {
            int result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[0].Text == ItemID)
                {
                    result = i;
                    return result;
                }
            }
            result = 101;
            return result;
        }
        private string getParentMixed(string ItemID)
        {
            string text = "";
            string result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[9].Text.Contains("\"" + ItemID + "\""))
                {
                    text = this.listView2.Items[i].SubItems[0].Text;
                    result = text;
                    return result;
                }
            }
            result = text;
            return result;
        }
        private string getParentName(string ItemID)
        {
            string text = "";
            string result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[9].Text.Contains("\"" + ItemID + "\""))
                {
                    text = this.listView2.Items[i].SubItems[1].Text;
                    result = text;
                    return result;
                }
            }
            result = text;
            return result;
        }
        private bool isParentItem(string ItemID)
        {
            bool result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[0].Text == ItemID && this.listView2.Items[i].SubItems[9].Text != "\"0\",")
                {
                    result = true;
                    return result;
                }
            }
            result = false;
            return result;
        }
        private bool isParentItem1(string ItemID)
        {
            bool result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[0].Text == ItemID)
                {
                    result = true;
                    return result;
                }
            }
            result = false;
            return result;
        }
        private int checkMixed(string ItemID)
        {
            int result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[9].Text.Contains("\"" + ItemID + "\""))
                {
                    result = i;
                    return result;
                }
            }
            result = -1;
            return result;
        }
        private int getItemIndex1(string ItemID)
        {
            int result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[0].Text == ItemID && this.listView2.Items[i].SubItems[8].Text != "")
                {
                    result = i;
                    return result;
                }
            }
            result = 101;
            return result;
        }
        private void SetRepDetailsNew()
        {
            this.txtSumAll.Text = "0";
            this.txtMoneyRoom.Text = "0";
            this.txtTotalMoney.Text = "0";
            this.txtMustPay.Text = "0";
            this.txtTienKMGH.Text = "0";
            this.txtKmGH.Text = "0";
            this.txtCusName.Text = "";
            this.txtPerPromote.Text = "0";
            this.txtMoneyPromote.Text = "0";
            this.txtVAT.Text = "0";
            this.lvProduct.Items.Clear();
            this.txtTotalPay.Text = "0";
            this.objFunc.SelectValueCombobox(this.cbbCustomer, "0");
        }
        private void listView1_Click(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[index].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                this.discount = float.Parse(this.listView1.FocusedItem.Group.Tag.ToString());
                this.CurrentRoomChanged = 0;
                this.MoneyRoomChanged = 0f;
                this.RoomStartDateTimeReal = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
                this.TPTimeStart.Enabled = false;
                this.SetRepDetailsNew();
                int itemIndex = this.getItemIndex(this.currRoomID);
                bool flag = this.CheckItemInList(this.currRoomID);
                if (flag)
                {
                    this.cmdStart.Enabled = false;
                    this.btnDel.Enabled = true;
                    this.TPTimeStart.Value = this.objR.getTimeStartRoomUsing(this.currRoomID);
                    this.CurrRoomTimeStart = this.TPTimeStart.Value;
                    int tempTimeUse = (int)DateTime.Now.Subtract(this.TPTimeStart.Value).TotalMinutes - this.objRoom.getMinitePause(int.Parse(this.currRoomID));
                    this.txtTimeUse.Text = tempTimeUse.ToString();
                    this.CmdAddRows.Enabled = true;
                    if (this.CanEdit)
                    {
                        this.btnEditTime.Enabled = true;
                        this.btnSaveEditTime.Enabled = false;
                    }
                    else
                    {
                        this.btnEditTime.Enabled = false;
                        this.btnSaveEditTime.Enabled = false;
                    }
                    this.loadService(index, this.currRoomID, this.lblRoomName.Text.Trim(), tempTimeUse);
                }
                else
                {
                    this.TPTimeStart.Value = DateTime.Now;
                    this.CurrRoomTimeStart = this.TPTimeStart.Value;
                    this.txtTimeUse.Text = "0";
                    this.cmdStart.Enabled = true;
                    this.btnDel.Enabled = false;
                    this.CmdAddRows.Enabled = false;
                    this.btnEditTime.Enabled = false;
                    this.btnSaveEditTime.Enabled = false;
                }
            }
            catch
            {
                this.currRoomID = "0";
            }
            if (this.listView1.SelectedItems.Count > 0)
            {
                this.listView1.ContextMenuStrip = this.contextMenuStrip1;
                if (this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].ImageIndex == 0 || this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].ImageIndex == 2)
                {
                    this.cTask1.Enabled = false;
                    this.cTask1.Visible = false;
                    this.tMnuForward.Visible = true;
                    this.tMnuForward.Enabled = true;
                    this.tMnuForward.Text = "Chuyển " + this.RoomName[int.Parse(this.lblCurrIndex.Text)].ToString() + " sang ";
                    this.cTask4.Enabled = true;
                    this.mnuPayment.Enabled = true;
                    this.tMnuDel.Enabled = true;
                    this.tsMnuPause.Visible = clsGeneral.Pause;
                    this.tsMnuPause.Enabled = clsGeneral.Pause;
                }
                else
                {
                    this.cTask1.Enabled = true;
                    this.cTask1.Visible = true;
                    this.tMnuForward.Enabled = false;
                    this.tMnuForward.Visible = true;
                    this.tMnuForward.Text = "Chuyển sân";
                    this.cTask4.Enabled = false;
                    this.mnuPayment.Enabled = false;
                    this.tMnuDel.Enabled = false;
                    this.tsMnuPause.Visible = false;
                    this.tsMnuPause.Enabled = false;
                }
            }
            else
            {
                this.listView1.ContextMenuStrip = null;
            }
        }
        private bool checkStopOrNot(string ItemID)
        {
            bool result;
            for (int i = 0; i < this.listView2.Items.Count; i++)
            {
                if (this.listView2.Items[i].SubItems[0].Text == ItemID && this.listView2.Items[i].SubItems[4].Text.Trim() != "")
                {
                    result = true;
                    return result;
                }
            }
            result = false;
            return result;
        }
        private void CloseRoom(string tempCurrRoom, int tempCurrIndex)
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand("updateOnTabRoomRent", sqlConnection);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add("@RoomID", SqlDbType.Int);
            sqlCommand.Parameters.Add("@TimeEnd", SqlDbType.DateTime);
            sqlCommand.Parameters.Add("@TimeUse", SqlDbType.Int);
            sqlCommand.Parameters.Add("@RoomMoney", SqlDbType.Float);
            sqlCommand.Parameters.Add("@Status", SqlDbType.SmallInt);
            sqlCommand.Parameters["@RoomID"].Value = int.Parse(tempCurrRoom);
            sqlCommand.Parameters["@TimeEnd"].Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
            TimeSpan timeSpan = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0).Subtract(DateTime.Parse(this.objR.getTimeStart(this.currRoomID)));
            sqlCommand.Parameters["@TimeUse"].Value = (int)timeSpan.TotalMinutes - this.objRoom.getMinitePause(int.Parse(tempCurrRoom));
            this.moneyRoom = this.objR.getMoneyRoomUsingChangedRoom(tempCurrRoom, this.TypePriceWhenChangeRoom);
            sqlCommand.Parameters["@RoomMoney"].Value = this.moneyRoom;
            sqlCommand.Parameters["@Status"].Value = 1;
            sqlCommand.ExecuteNonQuery();
            this.listView2.Items.Clear();
            SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
            sqlCommand2.CommandText = "SELECT * FROM [TabRoomRent] WHERE [Status] = 1 ";
            SqlDataReader sqlDataReader = sqlCommand2.ExecuteReader();
            this.Index = 0;
            while (sqlDataReader.Read())
            {
                this.listView2.Items.Add(sqlDataReader["RoomID"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader["RoomName"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(DateTime.Parse(sqlDataReader["TimeStart"].ToString()).ToString("HH:mm"));
                this.listView2.Items[this.Index].SubItems.Add(int.Parse(sqlDataReader["TimeUse"].ToString()).ToString());
                if (sqlDataReader["TimeEnd"].ToString() != "")
                {
                    try
                    {
                        this.listView2.Items[this.Index].SubItems.Add(DateTime.Parse(sqlDataReader["TimeEnd"].ToString()).ToString("HH:mm"));
                    }
                    catch
                    {
                        this.listView2.Items[this.Index].SubItems.Add("");
                    }
                }
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader["RoomMoney"].ToString())));
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader["ServiceMoney"].ToString())));
                float num = float.Parse(sqlDataReader["RoomMoney"].ToString()) + float.Parse(sqlDataReader["ServiceMoney"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", num));
                this.listView2.Items[this.Index].SubItems.Add("");
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader["GroupRoomID"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader["ChangedRoom"].ToString());
                this.Index++;
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
            this.listView2.Update();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.CheckItemInList(this.RoomID[i].ToString()))
                {
                    this.listView1.Items[i].ImageIndex = 0;
                    this.tsMnuPause.Enabled = clsGeneral.Pause;
                }
                else
                {
                    this.listView1.Items[i].ImageIndex = 1;
                    this.tsMnuPause.Enabled = false;
                }
            }
            this.listView1.Update();
        }
        private int getNumRoom()
        {
            int result = 0;
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            string cmdText = "SELECT COUNT(*) as Sophong FROM TabRoom";
            SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection);
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                result = int.Parse(sqlDataReader["Sophong"].ToString());
            }
            sqlDataReader.Close();
            sqlConnection.Close();
            sqlConnection.Dispose();
            return result;
        }
        private void Pay(string tempCurrRoomID, int currIndexTemp, string tempRoomName, bool printBill)
        {
            string text = "";
            try
            {
                //text = this.objReg.Insert("Win32_Processor");
            }
            catch
            {
                text = "";
            }
            if (text == "")
            {
                text = "31535552394A5A3";
            }
            string cDKey = text; //this.objReg.GetCDKey(text);
            int num = 0;
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = "SELECT count(RetailID) as RetailID FROM [TabRetailsList]";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                num = int.Parse(sqlDataReader["RetailID"].ToString());
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
            string text2 = ConfigurationSettings.AppSettings["License"].ToString();
            if (cDKey.ToUpper() == text2.ToUpper() || num < 50000)
            {
                this.Register = true;
            }
            if (num < 50)
            {
                this.Register = true;
            }
            else
            {
                this.Register = false;
            }
            if (this.Register)
            {
                try
                {
                    if (this.lblRoomName.Text.Trim() == "")
                    {
                        MessageBox.Show("Bạn chưa chọn sân cần thanh toán!\r\n\r\nVui lòng kiểm tra lại trước khi tiếp tục!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        if (this.listView1.Items[currIndexTemp].ImageIndex == 1)
                        {
                            MessageBox.Show("Bạn phải chọn một sân đã sử dụng để thanh toán!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else
                        {
                            this.currRoomID = tempCurrRoomID;
                            int itemIndex = this.getItemIndex(tempCurrRoomID);
                            if (itemIndex != 101)
                            {
                                string text3 = this.listView2.Items[itemIndex].SubItems[5].Text;
                                string text4 = this.listView2.Items[itemIndex].SubItems[2].Text;
                                string text5 = this.listView2.Items[itemIndex].SubItems[3].Text;
                                string text6 = this.listView2.Items[itemIndex].SubItems[4].Text;
                                this.txtRetailID.Text = this.objR.getRepID(tempCurrRoomID);
                                //frmSubKara.curBillId = this.txtRetailID.Text;
                                //frmRetailBillScrollCus.curBillId = this.txtRetailID.Text;
                                //frmBillScrollK801.curBillId = this.txtRetailID.Text;
                                //frmBillScrollK501.curBillId = this.txtRetailID.Text;
                                this.TimeStart = text4;
                                this.TimeUse = text5;
                                this.TimeEnd = text6;
                                this.SaveRep(2, tempRoomName, currIndexTemp, tempCurrRoomID, printBill);
                                //frmBanHang.doUpdate doUpdate = new frmBanHang.doUpdate(frmBanHang.getListBillNewest);
                                //doUpdate();
                            }
                            else
                            {
                                MessageBox.Show("Bạn chưa chọn sân cần thanh toán!\r\n\r\nVui lòng kiểm tra lại trước khi tiếp tục!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Bạn chưa chọn sân cần thanh toán!\r\n\r\nVui lòng kiểm tra lại trước khi tiếp tục!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("Bạn đang sử dụng phiên bản dùng thử!\r\n\r\nKhông thể tiếp tục sử dụng chức năng này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void ListView2Update()
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand("ActionOnTabRoomRent", sqlConnection);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add("@RoomID", SqlDbType.Int);
            sqlCommand.Parameters.Add("@RoomName", SqlDbType.NVarChar);
            sqlCommand.Parameters.Add("@TimeStart", SqlDbType.DateTime);
            sqlCommand.Parameters.Add("@Status", SqlDbType.SmallInt);
            sqlCommand.Parameters["@RoomID"].Value = int.Parse(this.currRoomID);
            sqlCommand.Parameters["@RoomName"].Value = this.objR.getName(this.currRoomID.ToUpper());
            sqlCommand.Parameters["@TimeStart"].Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
            sqlCommand.Parameters["@Status"].Value = 1;
            sqlCommand.ExecuteNonQuery();
            this.listView2.Items.Clear();
            SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
            sqlCommand2.CommandText = "SELECT * FROM [TabRoomRent] WHERE [Status] = 1 ";
            SqlDataReader sqlDataReader = sqlCommand2.ExecuteReader();
            this.Index = 0;
            while (sqlDataReader.Read())
            {
                this.listView2.Items.Add(sqlDataReader["RoomID"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader["RoomName"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(DateTime.Parse(sqlDataReader["TimeStart"].ToString()).ToString("HH:mm"));
                this.listView2.Items[this.Index].SubItems.Add(int.Parse(sqlDataReader["TimeUse"].ToString()).ToString());
                try
                {
                    this.listView2.Items[this.Index].SubItems.Add(DateTime.Parse(sqlDataReader["TimeEnd"].ToString()).ToString("HH:mm"));
                }
                catch
                {
                    this.listView2.Items[this.Index].SubItems.Add("");
                }
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader["RoomMoney"].ToString())));
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", float.Parse(sqlDataReader["ServiceMoney"].ToString())));
                float num = float.Parse(sqlDataReader["RoomMoney"].ToString()) + float.Parse(sqlDataReader["ServiceMoney"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(string.Format("{0:###,0}", num));
                this.listView2.Items[this.Index].SubItems.Add("");
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader["GroupRoomID"].ToString());
                this.listView2.Items[this.Index].SubItems.Add(sqlDataReader["ChangedRoom"].ToString());
                this.Index++;
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
            this.listView2.Update();
            for (int i = 0; i < this.listView1.Items.Count; i++)
            {
                if (this.CheckItemInList(this.RoomID[i].ToString()))
                {
                    this.listView1.Items[i].ImageIndex = 0;
                    this.tsMnuPause.Enabled = true;
                }
                else
                {
                    this.listView1.Items[i].ImageIndex = 1;
                    this.tsMnuPause.Enabled = false;
                }
            }
            this.listView1.Update();
        }
        private void tsMDel_Click(object sender, EventArgs e)
        {
            if (!this.Permission.Contains("67"))
            {
                MessageBox.Show("Bạn không có quyền hủy sân đã sử dụng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (this.lblRoomName.Text.Trim() == "")
                {
                    MessageBox.Show("Bạn chưa chọn sân cần xóa !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    if (MessageBox.Show("Bạn có chắc chắn muốn xóa sân " + this.lblRoomName.Text.ToUpper() + "  khỏi danh sách đang sử dụng không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        string tmpRoom = this.lblRoomName.Text.ToUpper();
                        string text = this.getParentMixed(this.currRoomID).ToString();
                        if (text.Length == 0)
                        {
                            string repID = this.objR.getRepID(this.currRoomID);
                            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
                            sqlConnection.Open();
                            SqlCommand sqlCommand = sqlConnection.CreateCommand();
                            sqlCommand.CommandText = "DELETE FROM [TabRoomRent] WHERE [RoomID] = " + this.currRoomID + " AND [Status] = 1 ";
                            sqlCommand.ExecuteNonQuery();
                            if (repID != "")
                            {
                                sqlCommand.CommandText = string.Concat(new string[]
								{
									"DELETE FROM [TabRetailsList] WHERE [RetailID] = '",
									repID,
									"' DELETE FROM [TabRetailsLink] WHERE  [RetailID]='",
									repID,
									"' "
								});
                                sqlCommand.ExecuteNonQuery();
                            }
                            sqlConnection.Close();
                            sqlConnection.Dispose();
                            int itemIndex = this.getItemIndex(this.currRoomID);
                            if (itemIndex != 101)
                            {
                                this.listView2.Items[itemIndex].Remove();
                                this.listView2.Refresh();
                            }
                            for (int i = 0; i < this.listView1.Items.Count; i++)
                            {
                                if (this.CheckItemInList(this.RoomID[i].ToString()))
                                {
                                    this.listView1.Items[i].ImageIndex = 0;
                                }
                                else
                                {
                                    this.listView1.Items[i].ImageIndex = 1;
                                }
                            }
                            this.objRoom.delPause(int.Parse(this.currRoomID));
                        }
                        else
                        {
                            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
                            sqlConnection.Open();
                            SqlCommand sqlCommand = sqlConnection.CreateCommand();
                            sqlCommand.CommandText = string.Concat(new string[]
							{
								"UPDATE [TabRoomRent] SET [GroupRoomID] = REPLACE(GroupRoomID  COLLATE Latin1_General_BIN,',\"",
								this.currRoomID,
								"\"','') WHERE [RoomID] = ",
								text,
								" AND [Status] = 1 "
							});
                            sqlCommand.ExecuteNonQuery();
                            sqlConnection.Close();
                            sqlConnection.Dispose();
                        }
                        this.SaveLog(tmpRoom, 3);
                        this.lvProduct.Items.Clear();
                        this.ReFresh();
                        this.txtSumAll.Text = "0";
                        this.txtMoneyRoom.Text = "0";
                        this.txtMustPay.Text = "0";
                        this.txtKmGH.Text = "0";
                        this.txtPerPromote.Text = "0";
                        this.txtOtherPercent.Text = "0";
                        this.txtVAT.Text = "0";
                        this.lblRoomName.Text = "";
                        this.txtTimeUse.Text = "0";
                    }
                }
            }
        }
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                if (this.listView1.FocusedItem.ImageIndex == 0)
                {
                    if (MessageBox.Show("Bạn có muốn thanh toán tiền cho sân " + this.lblRoomName.Text.ToUpper() + " \r\n\r\nĐồng thời xoá sân khỏi danh sách chờ thanh toán không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.objRoom.finishAllPause(int.Parse(this.currRoomID));
                        this.CloseRoom(this.currRoomID, index);
                        this.btnSaveCus.PerformClick();
                        this.Pay(this.currRoomID, index, this.lblRoomName.Text, true);
                    }
                }
                else
                {
                    if (this.listView1.FocusedItem.ImageIndex == 2)
                    {
                        MessageBox.Show("Sân đang bị tạm dừng sử dụng\r\n\r\nBạn hãy tiếp tục sử dụng trước khi thanh toán !", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        if (MessageBox.Show("Bạn có muốn bắt đầu sử dụng sân " + this.lblRoomName.Text.ToUpper() + " không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            this.cmdStart.PerformClick();
                        }
                    }
                }
            }
            catch
            {
                this.listView1.Enabled = true;
            }
        }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[index].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                this.discount = float.Parse(this.listView1.FocusedItem.Group.Tag.ToString());
                this.CurrentRoomChanged = 0;
                this.MoneyRoomChanged = 0f;
                this.RoomStartDateTimeReal = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
                this.TPTimeStart.Enabled = false;
                this.SetRepDetailsNew();
                int itemIndex = this.getItemIndex(this.currRoomID);
                bool flag = this.CheckItemInList(this.currRoomID);
                if (flag)
                {
                    this.cmdStart.Enabled = false;
                    this.tsMnuPause.Enabled = clsGeneral.Pause;
                    this.btnDel.Enabled = true;
                    this.TPTimeStart.Value = this.objR.getTimeStartRoomUsing(this.currRoomID);
                    this.CurrRoomTimeStart = this.TPTimeStart.Value;
                    int tempTimeUse = (int)DateTime.Now.Subtract(this.TPTimeStart.Value).TotalMinutes - this.objRoom.getMinitePause(int.Parse(this.currRoomID));
                    this.txtTimeUse.Text = tempTimeUse.ToString();
                    this.CmdAddRows.Enabled = true;
                    if (this.CanEdit)
                    {
                        this.btnEditTime.Enabled = true;
                        this.btnSaveEditTime.Enabled = false;
                    }
                    if (this.objRoom.checkRoomPause(int.Parse(this.currRoomID)))
                    {
                        this.tsMnuPause.Text = "Tiếp tục";
                        this.cTask4.Enabled = false;
                        this.mnuPayment.Enabled = false;
                    }
                    else
                    {
                        this.tsMnuPause.Text = "Tạm dừng";
                        this.cTask4.Enabled = true;
                        this.mnuPayment.Enabled = true;
                    }
                    this.loadService(index, this.currRoomID, this.lblRoomName.Text.Trim(), tempTimeUse);
                    this.btnEmp.Text = "PV : " + this.objRoom.getEmp(this.txtRetailID.Text);
                }
                else
                {
                    this.TPTimeStart.Value = DateTime.Now;
                    this.CurrRoomTimeStart = this.TPTimeStart.Value;
                    this.txtTimeUse.Text = "0";
                    this.cmdStart.Enabled = true;
                    this.tsMnuPause.Enabled = false;
                    this.btnDel.Enabled = false;
                    this.CmdAddRows.Enabled = false;
                    this.btnEditTime.Enabled = false;
                    this.btnSaveEditTime.Enabled = false;
                }
            }
            catch
            {
                this.currRoomID = "0";
            }
        }
        private void cTask1_Click(object sender, EventArgs e)
        {
            this.cmdStart.PerformClick();
        }
        private void cTask4_Click(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                if (this.objRoom.checkRoomPause(int.Parse(this.currRoomID)))
                {
                    MessageBox.Show("Sân đang bị tạm dừng sử dụng\r\n\r\nBạn hãy tiếp tục sử dụng trước khi thanh toán !", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    if (MessageBox.Show("Bạn có muốn thanh toán tiền cho sân " + this.lblRoomName.Text.ToUpper() + " không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.objRoom.finishAllPause(int.Parse(this.currRoomID));
                        this.CloseRoom(this.currRoomID, index);
                        this.btnSaveCus.PerformClick();
                        this.Pay(this.currRoomID, index, this.lblRoomName.Text, true);
                    }
                }
            }
            catch
            {
            }
        }
        private void cTask5_Click(object sender, EventArgs e)
        {
            this.ReFresh();
        }
        private void tMnuDel_Click(object sender, EventArgs e)
        {
            this.btnDel.PerformClick();
        }
        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                if (this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].ImageIndex == 0)
                {
                    for (int i = 0; i < this.listView1.Items.Count; i++)
                    {
                        if (i != int.Parse(this.lblCurrIndex.Text))
                        {
                            if (this.checkMixed(this.RoomID[i].ToString()) == -1)
                            {
                                if (this.listView1.Items[i].ImageIndex == 1)
                                {
                                    ToolStripMenuItem value = new ToolStripMenuItem(this.RoomName[i].ToString(), this.imageList1.Images[1], new EventHandler(this.itemMnu_Click), this.RoomID[i].ToString());
                                    this.tMnuForward.DropDownItems.Add(value);
                                }
                            }
                        }
                    }
                }
            }
        }
        private void contextMenuStrip1_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            this.tMnuForward.DropDownItems.Clear();
        }
        private void itemMnu_Click(object sender, EventArgs e)
        {
            ToolStripItem toolStripItem = (ToolStripItem)sender;
            int num = this.checkMixed(this.currRoomID);
            if (num != -1)
            {
                MessageBox.Show("Sân này đã được gộp dịch vụ vào sân " + this.objR.getName(this.getParentMixed(this.currRoomID)), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string text = this.RoomName[int.Parse(this.lblCurrIndex.Text)];
                if (MessageBox.Show("Bạn có muốn chuyển tất cả dịch vụ đang sử dụng từ sân \r\n\r\n" + text + "\r\n\r\n sang sân \r\n\r\n" + toolStripItem.Text, "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    float moneyRoomUsingChangedRoom = this.objR.getMoneyRoomUsingChangedRoom(this.currRoomID, this.TypePriceWhenChangeRoom);
                    this.objR.forWardRoom(this.currRoomID, toolStripItem.Name, toolStripItem.Text, moneyRoomUsingChangedRoom, text);
                    this.SaveLogMove(text, toolStripItem.Text);
                    this.ReFresh();
                }
            }
        }
        private void itemMixed_Click(object sender, EventArgs e)
        {
            ToolStripItem toolStripItem = (ToolStripItem)sender;
            int num = this.checkMixed(this.currRoomID);
            if (num != -1)
            {
                MessageBox.Show("Sân này đã được gộp dịch vụ vào bàn " + this.objR.getName(this.getParentMixed(this.currRoomID)), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (MessageBox.Show("Bạn muốn nhập tất cả dịch vụ đang sử dụng từ bàn \r\n\r\n" + toolStripItem.Text + "\r\n\r\n sang bàn \r\n\r\n" + this.RoomName[int.Parse(this.lblCurrIndex.Text)], "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (!this.checkInRetailList(toolStripItem.Name))
                    {
                        this.updateGroupRoomID(this.currRoomID, toolStripItem.Name);
                    }
                    else
                    {
                        int itemIndex = this.getItemIndex(this.currRoomID);
                        if (itemIndex == 101)
                        {
                            MessageBox.Show("Chọn một bàn đã sử dụng để nhập vào bàn này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        if (!this.checkInRetailList(this.currRoomID) && this.checkInRetailList(toolStripItem.Name))
                        {
                            this.objR.mixedRoom(toolStripItem.Name, this.currRoomID);
                        }
                        else
                        {
                            this.objR.mixedRoom(this.currRoomID, toolStripItem.Name);
                        }
                    }
                    this.ReFresh();
                }
            }
        }
        private void listView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Delete")
            {
                this.btnDel.PerformClick();
            }
            else
            {
                if (e.KeyCode == Keys.Return)
                {
                    try
                    {
                        int index = this.listView1.FocusedItem.Index;
                        this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                        string[] array = this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].SubItems[0].Text.Split(new char[]
						{
							'-'
						});
                        this.lblRoomName.Text = array[0];
                        this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                        if (this.listView1.FocusedItem.ImageIndex == 0)
                        {
                            if (MessageBox.Show("Bạn có muốn thanh toán tiền cho sân " + this.lblRoomName.Text.ToUpper() + " \r\n\r\nĐồng thời xoá sân khỏi danh sách chờ thanh toán không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                this.objRoom.finishAllPause(int.Parse(this.currRoomID));
                                this.CloseRoom(this.currRoomID, index);
                                this.btnSaveCus.PerformClick();
                                this.Pay(this.currRoomID, index, this.lblRoomName.Text, true);
                            }
                        }
                        else
                        {
                            if (this.listView1.FocusedItem.ImageIndex == 2)
                            {
                                MessageBox.Show("Sân đang bị tạm dừng sử dụng\r\n\r\nBạn hãy tiếp tục sử dụng trước khi thanh toán !", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            else
                            {
                                if (MessageBox.Show("Bạn có muốn bắt đầu sử dụng sân " + this.lblRoomName.Text.ToUpper() + " không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    this.cmdStart.PerformClick();
                                }
                            }
                        }
                    }
                    catch
                    {
                        this.listView1.Enabled = true;
                    }
                }
                else
                {
                    if (e.KeyCode == Keys.F5)
                    {
                        this.lvProduct.Focus();
                    }
                }
            }
        }
        private bool checkInRetailList(string roomID)
        {
            bool result = false;
            Func func = new Func();
            SqlConnection sqlConnection = new SqlConnection(func.strConnectionString);
            SqlCommand sqlCommand = new SqlCommand("SELECT TOP 1 [RepID] FROM [TabRoomRent] WHERE [RoomID] = " + roomID + " AND [Status] = 1", sqlConnection);
            sqlConnection.Open();
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            if (sqlDataReader.HasRows)
            {
                while (sqlDataReader.Read())
                {
                    result = !(sqlDataReader["RepID"].ToString() == "");
                }
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
            return result;
        }
        private void updateGroupRoomID(string roomIdRoot, string roomIdChild)
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            roomIdChild = "+'\"" + roomIdChild + "\",'";
            SqlCommand sqlCommand = new SqlCommand("UPDATE [TabRoomRent] SET [GroupRoomID] = [GroupRoomID] " + roomIdChild + " WHERE [roomID] = " + roomIdRoot, sqlConnection);
            sqlCommand.ExecuteNonQuery();
            SqlCommand sqlCommand2 = new SqlCommand("DELETE [TabRoomRent] WHERE [Status] = 1 AND [roomID] = " + roomIdChild.Replace(",", "").Replace("\"", "").Replace("'", ""), sqlConnection);
            sqlCommand2.ExecuteNonQuery();
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private void tMnuRefresh_Click(object sender, EventArgs e)
        {
            this.AddGroup();
            this.ReFresh();
        }
        private int checkInBill(string pid)
        {
            int result;
            for (int i = 0; i < this.lvProduct.Items.Count; i++)
            {
                if (pid == this.lvProduct.Items[i].SubItems[0].Text)
                {
                    result = i;
                    return result;
                }
            }
            result = -1;
            return result;
        }
        private void searchProduct(string searchFor)
        {
            this.dgvProducts.AutoGenerateColumns = false;
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            SqlConnection sqlConnection2 = new SqlConnection(this.objFunc.strConnectionString);
            string text;
            if (searchFor != "")
            {
                text = string.Concat(new string[]
				{
					" AND (UPPER([TabProducts].[ShortName]) LIKE N'%",
					searchFor.ToUpper(),
					"%' OR UPPER([TabProducts].[NameForSearch]) LIKE N'%",
					searchFor.ToUpper(),
					"%'  OR UPPER([TabProducts].[P_Name]) LIKE N'%",
					searchFor.ToUpper(),
					"%') "
				});
            }
            else
            {
                text = " ";
            }
            DataTable dataTable = new DataTable();
            DataColumn column = new DataColumn("PID", typeof(string));
            DataColumn column2 = new DataColumn("P_Name", typeof(string));
            DataColumn column3 = new DataColumn("P_DonViTinh", typeof(string));
            DataColumn column4 = new DataColumn("P_PriceRetail", typeof(string));
            DataColumn column5 = new DataColumn("P_PriceTrade", typeof(string));
            DataColumn column6 = new DataColumn("UnitChild", typeof(string));
            DataColumn column7 = new DataColumn("UnitNumber", typeof(string));
            dataTable.Columns.Add(column);
            dataTable.Columns.Add(column2);
            dataTable.Columns.Add(column3);
            dataTable.Columns.Add(column4);
            dataTable.Columns.Add(column5);
            dataTable.Columns.Add(column6);
            dataTable.Columns.Add(column7);
            sqlConnection.Open();
            sqlConnection2.Open();
            SqlCommand sqlCommand = sqlConnection2.CreateCommand();
            sqlCommand.CommandText = "SELECT * FROM TabGproducts WHERE GpId IN (SELECT GpId FROM TabProducts) ORDER BY GpName";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                dataTable.Rows.Add(new object[]
				{
					"",
					"+ " + sqlDataReader["GpName"].ToString().ToUpper(),
					"",
					"",
					"",
					"",
					""
				});
                string cmdText = string.Concat(new string[]
				{
					"SELECT [TabProducts].[P_Name] as P_Name,[TabProducts].[PID] as PID,[TabProducts].[P_PriceRetail] as P_PriceRetail,[TabProducts].[P_PriceTrade] as P_PriceTrade,[TabProducts].[P_DonViTinh] as P_DonViTinh,[TabUnitProduct].[UnitChild] as UnitChild,[TabUnitProduct].[UnitNumber] as UnitNumber FROM [TabProducts],[TabUnitProduct]  WHERE [TabProducts].[P_DonViTinh]=[TabUnitProduct].[UnitID] ",
					text,
					" AND GpId = ",
					sqlDataReader["GpId"].ToString(),
					" ORDER BY GpID,[TabProducts].[P_Name]"
				});
                SqlCommand sqlCommand2 = new SqlCommand(cmdText, sqlConnection);
                SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
                while (sqlDataReader2.Read())
                {
                    dataTable.Rows.Add(new object[]
					{
						sqlDataReader2["PID"].ToString(),
						sqlDataReader2["P_Name"].ToString(),
						sqlDataReader2["P_DonViTinh"].ToString(),
						sqlDataReader2["P_PriceRetail"].ToString(),
						sqlDataReader2["P_PriceTrade"].ToString(),
						sqlDataReader2["UnitChild"].ToString(),
						sqlDataReader2["UnitNumber"].ToString()
					});
                }
                sqlDataReader2.Close();
            }
            sqlDataReader.Close();
            this.dgvProducts.DataSource = dataTable;
            sqlConnection.Close();
            sqlConnection.Dispose();
            sqlConnection2.Close();
            sqlConnection2.Dispose();
        }
        private void searchProductAffterAdd(string searchFor)
        {
            this.dgvProducts.AutoGenerateColumns = false;
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            SqlConnection sqlConnection2 = new SqlConnection(this.objFunc.strConnectionString);
            DataTable dataTable = new DataTable();
            DataColumn column = new DataColumn("PID", typeof(string));
            DataColumn column2 = new DataColumn("P_Name", typeof(string));
            DataColumn column3 = new DataColumn("P_DonViTinh", typeof(string));
            DataColumn column4 = new DataColumn("P_PriceRetail", typeof(string));
            DataColumn column5 = new DataColumn("P_PriceTrade", typeof(string));
            DataColumn column6 = new DataColumn("UnitChild", typeof(string));
            DataColumn column7 = new DataColumn("UnitNumber", typeof(string));
            dataTable.Columns.Add(column);
            dataTable.Columns.Add(column2);
            dataTable.Columns.Add(column3);
            dataTable.Columns.Add(column4);
            dataTable.Columns.Add(column5);
            dataTable.Columns.Add(column6);
            dataTable.Columns.Add(column7);
            sqlConnection.Open();
            sqlConnection2.Open();
            SqlCommand sqlCommand = sqlConnection2.CreateCommand();
            sqlCommand.CommandText = "SELECT * FROM TabGproducts WHERE GpId IN (SELECT GpId FROM TabProducts WHERE P_Name = N'" + searchFor + "') ORDER BY GpName";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                dataTable.Rows.Add(new object[]
				{
					"",
					"+ " + sqlDataReader["GpName"].ToString().ToUpper(),
					"",
					"",
					"",
					"",
					""
				});
                string cmdText = string.Concat(new string[]
				{
					"SELECT [TabProducts].[P_Name] as P_Name,[TabProducts].[PID] as PID,[TabProducts].[P_PriceRetail] as P_PriceRetail,[TabProducts].[P_PriceTrade] as P_PriceTrade,[TabProducts].[P_DonViTinh] as P_DonViTinh,[TabUnitProduct].[UnitChild] as UnitChild,[TabUnitProduct].[UnitNumber] as UnitNumber FROM [TabProducts],[TabUnitProduct]  WHERE [TabProducts].[P_DonViTinh]=[TabUnitProduct].[UnitID] AND P_Name = N'",
					searchFor,
					"' AND GpId = ",
					sqlDataReader["GpId"].ToString(),
					" ORDER BY GpID,[TabProducts].[P_Name]"
				});
                SqlCommand sqlCommand2 = new SqlCommand(cmdText, sqlConnection);
                SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
                while (sqlDataReader2.Read())
                {
                    dataTable.Rows.Add(new object[]
					{
						sqlDataReader2["PID"].ToString(),
						sqlDataReader2["P_Name"].ToString(),
						sqlDataReader2["P_DonViTinh"].ToString(),
						sqlDataReader2["P_PriceRetail"].ToString(),
						sqlDataReader2["P_PriceTrade"].ToString(),
						sqlDataReader2["UnitChild"].ToString(),
						sqlDataReader2["UnitNumber"].ToString()
					});
                }
                sqlDataReader2.Close();
            }
            sqlDataReader.Close();
            this.dgvProducts.DataSource = dataTable;
            sqlConnection.Close();
            sqlConnection.Dispose();
            sqlConnection2.Close();
            sqlConnection2.Dispose();
        }
        private void btlExit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát khỏi chương trình này không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }
        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            this.lvp0.Width = 0;
            this.lvp8.Width = 0;
            this.lvp1.Width = this.lvProduct.Width - (this.lvp0.Width + this.lvp2.Width + this.lvp3.Width + this.lvp4.Width + this.lvp5.Width + this.lvp6.Width + this.lvp7.Width + 23);
        }
        private void SaveRep(int TypeSave, string tempRoomName, int tempCurrIndex, string tempCurrRoomID, bool printBill)
        {
            if (this.lblRoomName.Text.Trim() == "")
            {
                MessageBox.Show("Chưa sân nào được chọn để cập nhật", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (this.listView1.Items[tempCurrIndex].ImageIndex == 1)
                {
                    MessageBox.Show("Bạn phải chọn sân đang được sử dụng để cập nhật", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    if (!this.isParentItem1(tempCurrRoomID))
                    {
                        tempCurrRoomID = this.getParentMixed(tempCurrRoomID);
                    }
                    this.currRoomID = tempCurrRoomID;
                    this.CurrRoomName = tempRoomName;
                    if (TypeSave == 2)
                    {
                        this.saveReport(2, tempCurrRoomID, tempRoomName);
                        if (printBill)
                        {
                            this.PrintRep(tempCurrRoomID, tempCurrIndex, tempRoomName);
                        }
                        this.SaveLog(tempRoomName, 5);
                        this.ReFresh();
                        this.SetRepDetailsNew();
                        this.lvProduct.Items.Clear();
                    }
                    else
                    {
                        if (TypeSave == 1)
                        {
                            this.saveReport(1, tempCurrRoomID, tempRoomName);
                        }
                    }
                    this.dgvProducts.Focus();
                }
            }
        }
        private void saveReport(int RoomStatus, string roomID, string tempRoomName)
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand("ActionOnTabRetailsList", sqlConnection);
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Add("@RetailID", SqlDbType.VarChar, 50);
            sqlCommand.Parameters["@RetailID"].Direction = ParameterDirection.InputOutput;
            sqlCommand.Parameters.Add("@RetailDate", SqlDbType.DateTime);
            sqlCommand.Parameters.Add("@WHID", SqlDbType.VarChar);
            sqlCommand.Parameters.Add("@FormPayID", SqlDbType.SmallInt);
            sqlCommand.Parameters.Add("@Note", SqlDbType.NVarChar);
            sqlCommand.Parameters.Add("@CusName", SqlDbType.NVarChar);
            sqlCommand.Parameters.Add("@EmpID", SqlDbType.VarChar);
            sqlCommand.Parameters.Add("@RoomID", SqlDbType.Int);
            sqlCommand.Parameters.Add("@RoomStatus", SqlDbType.Int);
            sqlCommand.Parameters.Add("@Promote", SqlDbType.Float);
            sqlCommand.Parameters.Add("@PerPromote", SqlDbType.Float);
            sqlCommand.Parameters.Add("@TotalMoney", SqlDbType.Float);
            sqlCommand.Parameters.Add("@ServiceMoney", SqlDbType.Float);
            sqlCommand.Parameters.Add("@DateShort", SqlDbType.DateTime);
            sqlCommand.Parameters.Add("@PerPromoteTime", SqlDbType.Float);
            sqlCommand.Parameters.Add("@PromoteTime", SqlDbType.Float);
            sqlCommand.Parameters.Add("@VAT", SqlDbType.Float);
            sqlCommand.Parameters.Add("@PartnerID", SqlDbType.Int);
            sqlCommand.Parameters.Add("@TotalPay", SqlDbType.Float);
            sqlCommand.Parameters.Add("@OtherMoney", SqlDbType.Float);
            sqlCommand.Parameters["@RetailID"].Value = this.txtRetailID.Text;
            sqlCommand.Parameters["@RetailDate"].Value = DateTime.Now;
            sqlCommand.Parameters["@WHID"].Value = this.cbBWareHouse.SelectedValue.ToString();
            sqlCommand.Parameters["@FormPayID"].Value = 1;
            sqlCommand.Parameters["@Note"].Value = this.txtOrderNote.Text;
            if (this.txtCusName.Text.Trim() != "")
            {
                sqlCommand.Parameters["@CusName"].Value = this.txtCusName.Text;
            }
            else
            {
                sqlCommand.Parameters["@CusName"].Value = this.objR.gettempRoomName(roomID);
            }
            sqlCommand.Parameters["@EmpID"].Value = this.UserName;
            sqlCommand.Parameters["@RoomID"].Value = int.Parse(roomID);
            sqlCommand.Parameters["@RoomStatus"].Value = RoomStatus;
            try
            {
                sqlCommand.Parameters["@Promote"].Value = double.Parse(this.txtMoneyPromote.Text);
            }
            catch
            {
                sqlCommand.Parameters["@Promote"].Value = "0";
            }
            sqlCommand.Parameters["@PerPromote"].Value = this.txtPerPromote.Text;
            sqlCommand.Parameters["@TotalMoney"].Value = double.Parse(this.txtTotalMoney.Text.Trim());
            sqlCommand.Parameters["@ServiceMoney"].Value = double.Parse(this.txtSumAll.Text.Trim());
            sqlCommand.Parameters["@DateShort"].Value = DateTime.Now.ToShortDateString();
            sqlCommand.Parameters["@PerPromoteTime"].Value = double.Parse(this.txtKmGH.Text.Trim());
            sqlCommand.Parameters["@PromoteTime"].Value = double.Parse(this.txtTienKMGH.Text);
            sqlCommand.Parameters["@VAT"].Value = double.Parse(this.txtVAT.Text);
            ItemCombobox itemCombobox = (ItemCombobox)this.cbbCustomer.SelectedItem;
            sqlCommand.Parameters["@PartnerID"].Value = itemCombobox.Value;
            if (itemCombobox.Value == "0")
            {
                sqlCommand.Parameters["@TotalPay"].Value = double.Parse(this.txtTotalPay.Text);
            }
            else
            {
                sqlCommand.Parameters["@TotalPay"].Value = double.Parse(this.txtTotalPay.Text);
            }
            sqlCommand.Parameters["@OtherMoney"].Value = double.Parse(this.txtOrtherMoney.Text);
            sqlCommand.ExecuteNonQuery();
            this.txtRetailID.Text = sqlCommand.Parameters["@RetailID"].Value.ToString();
            this.objRoom.setBillIdPause(int.Parse(roomID), this.txtRetailID.Text);
            sqlConnection.Close();
            sqlConnection.Dispose();
            if (RoomStatus == 2)
            {
                this.SaveTabReceipt(double.Parse(this.txtTotalPay.Text));
            }
            this.saveRepLink(RoomStatus);
            this.currRoomID = roomID;
        }
        private void saveRepLink(int status)
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = " DELETE FROM TabRetailsLink WHERE [RetailID]='" + this.txtRetailID.Text + "' ";
            sqlCommand.ExecuteNonQuery();
            SqlCommand sqlCommand2 = new SqlCommand("ActionOnTabRetailsLink", sqlConnection);
            sqlCommand2.CommandType = CommandType.StoredProcedure;
            sqlCommand2.Parameters.Add("@RetailID", SqlDbType.VarChar);
            sqlCommand2.Parameters.Add("@ProID", SqlDbType.Int);
            sqlCommand2.Parameters.Add("@ProName", SqlDbType.NVarChar, 300);
            sqlCommand2.Parameters.Add("@PDonViTinh", SqlDbType.NVarChar, 200);
            sqlCommand2.Parameters.Add("@whID", SqlDbType.VarChar, 50);
            sqlCommand2.Parameters.Add("@Price", SqlDbType.Float);
            sqlCommand2.Parameters.Add("@Number", SqlDbType.Int);
            sqlCommand2.Parameters.Add("@TotalMoney", SqlDbType.Float);
            sqlCommand2.Parameters.Add("@Status", SqlDbType.SmallInt);
            sqlCommand2.Parameters.Add("@OrderNumber", SqlDbType.Int);
            sqlCommand2.Parameters.Add("@UnitName", SqlDbType.NVarChar, 300);
            if (status == 2)
            {
                this.CreateTable();
            }
            for (int i = 0; i < this.lvProduct.Items.Count; i++)
            {
                if (double.Parse(this.lvProduct.Items[i].SubItems[5].Text) > 0.0)
                {
                    if (status == 2)
                    {
                        this.objTable.Rows.Add(new object[]
						{
							this.lvProduct.Items[i].SubItems[1].Text,
							this.lvProduct.Items[i].SubItems[2].Text,
							int.Parse(this.lvProduct.Items[i].SubItems[5].Text),
							float.Parse(this.lvProduct.Items[i].SubItems[6].Text.Replace(".", "").Replace(",", "")),
							float.Parse(this.lvProduct.Items[i].SubItems[7].Text.Replace(".", "").Replace(",", ""))
						});
                    }
                    sqlCommand2.Parameters["@RetailID"].Value = this.txtRetailID.Text;
                    sqlCommand2.Parameters["@ProID"].Value = int.Parse(this.lvProduct.Items[i].SubItems[0].Text);
                    sqlCommand2.Parameters["@ProName"].Value = this.lvProduct.Items[i].SubItems[1].Text;
                    sqlCommand2.Parameters["@PDonViTinh"].Value = this.lvProduct.Items[i].SubItems[8].Text;
                    sqlCommand2.Parameters["@Number"].Value = int.Parse(this.lvProduct.Items[i].SubItems[5].Text);
                    sqlCommand2.Parameters["@Price"].Value = float.Parse(this.lvProduct.Items[i].SubItems[6].Text.Replace(".", "").Replace(",", ""));
                    sqlCommand2.Parameters["@TotalMoney"].Value = float.Parse(this.lvProduct.Items[i].SubItems[7].Text.Replace(".", "").Replace(",", ""));
                    sqlCommand2.Parameters["@whID"].Value = this.cbBWareHouse.SelectedValue.ToString();
                    sqlCommand2.Parameters["@Status"].Value = status;
                    sqlCommand2.Parameters["@OrderNumber"].Value = i;
                    sqlCommand2.Parameters["@UnitName"].Value = this.lvProduct.Items[i].SubItems[2].Text;
                    sqlCommand2.ExecuteNonQuery();
                }
            }
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private void SaveTabReceipt(double TotalPay)
        {
            try
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand("ActionOnTabReceipt", sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@RecID", SqlDbType.NVarChar);
                sqlCommand.Parameters["@RecID"].Direction = ParameterDirection.InputOutput;
                sqlCommand.Parameters.Add("@RecDate", SqlDbType.DateTime);
                sqlCommand.Parameters.Add("@RecRoot", SqlDbType.NVarChar, 50);
                sqlCommand.Parameters.Add("@RecItemID", SqlDbType.NVarChar, 50);
                sqlCommand.Parameters.Add("@Customer_ID", SqlDbType.NVarChar, 50);
                sqlCommand.Parameters.Add("@RecPayer", SqlDbType.NVarChar, 200);
                sqlCommand.Parameters.Add("@RecMoney", SqlDbType.Float);
                sqlCommand.Parameters.Add("@RecNotes", SqlDbType.NVarChar, 500);
                sqlCommand.Parameters["@RecID"].Value = "";
                sqlCommand.Parameters["@RecDate"].Value = DateTime.Now.ToShortDateString();
                sqlCommand.Parameters["@RecRoot"].Value = this.txtRetailID.Text;
                sqlCommand.Parameters["@RecItemID"].Value = "4";
                sqlCommand.Parameters["@Customer_ID"].Value = this.txtCusName.Text;
                sqlCommand.Parameters["@RecPayer"].Value = this.FullName;
                sqlCommand.Parameters["@RecMoney"].Value = TotalPay;
                sqlCommand.Parameters["@RecNotes"].Value = this.txtOrderNote.Text;
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void tMnuDel1_Click(object sender, EventArgs e)
        {
            this.DeleteRowsSelected();
            this.setNew();
        }
        private void setNew()
        {
            this.txtProductID.Text = "";
            this.txtProductName.Text = "";
            this.txtNumber.Text = "0";
            this.txtStandPrice.Text = "0";
            this.txtSoLe.Text = "0";
            this.txtMoneyItem.Text = "0";
            this.cbbUnit.SelectedIndex = 0;
        }
        private float CheckMoney()
        {
            float num = 0f;
            if (this.lvProduct.Items.Count > 0)
            {
                try
                {
                    for (int i = 0; i < this.lvProduct.Items.Count; i++)
                    {
                        num += float.Parse(this.lvProduct.Items[i].SubItems[7].Text.Replace(",", "").Replace(".", ""));
                    }
                }
                catch
                {
                }
            }
            return num;
        }
        private void DeleteRowsSelected()
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    while (this.lvProduct.SelectedItems.Count > 0)
                    {
                        int index = this.lvProduct.SelectedItems[0].Index;
                        this.lvProduct.Items[index].Remove();
                        this.Index--;
                    }
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
            else
            {
                MessageBox.Show("Chưa chọn mục để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
        private void MnuAdd5_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) + 5).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) + 5).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuAdd4_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) + 4).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) + 4).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuAdd3_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) + 3).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) + 3).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuAdd2_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) + 2).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) + 2).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuAdd1_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) + 1).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) + 1).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuDel1_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) - 1).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) - 1).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuDel2_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) - 2).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) - 2).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuDel3_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) - 3).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) - 3).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuDel4_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) - 4).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) - 4).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void MnuDel5_Click(object sender, EventArgs e)
        {
            if (this.lvProduct.SelectedItems.Count > 0)
            {
                try
                {
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) - 5).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) - 5).ToString();
                    this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void tMnuNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return && this.lvProduct.SelectedItems.Count > 0)
            {
                if (this.tMnuNumber.Text != "")
                {
                    try
                    {
                        this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) + int.Parse(this.tMnuNumber.Text)).ToString();
                        this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) + int.Parse(this.tMnuNumber.Text)).ToString();
                        this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                        this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                        this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                        this.tMnuNumber.Text = "";
                    }
                    catch
                    {
                    }
                }
            }
        }
        private void tTxtDel_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return && this.lvProduct.SelectedItems.Count > 0)
            {
                if (this.tTxtDel.Text != "")
                {
                    try
                    {
                        this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[4].Text) - int.Parse(this.tTxtDel.Text)).ToString();
                        this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text = (int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) - int.Parse(this.tTxtDel.Text)).ToString();
                        this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[5].Text) * float.Parse(this.lvProduct.Items[this.lvProduct.FocusedItem.Index].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                        this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                        this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                        this.tTxtDel.Text = "";
                    }
                    catch
                    {
                    }
                }
            }
        }
        private void PrintRep(string tempCurrRoomID, int tempCurrIndex, string tempRoomName)
        {
            if (this.txtCusName.Text.Trim() == "")
            {
                this.txtCusName.Text = tempRoomName;
            }
            this.currRoomID = tempCurrRoomID;
            if (!this.isParentItem1(tempCurrRoomID))
            {
                this.currRoomID = this.getParentMixed(tempCurrRoomID);
            }
            try
            {
                //frmReportViewer frmReportViewer = new frmReportViewer();
                //frmReportViewer.WindowState = FormWindowState.Maximized;
                //string a = "5";
                //try
                //{
                //    a = ConfigurationSettings.AppSettings["Print"].ToString();
                //}
                //catch
                //{
                //}
                //if (a == "5")
                //{
                //    frmReportViewer.srptType = "RetailPrintA5";
                //}
                //else
                //{
                //    if (this.txtKmGH.Text.Trim() == "0" && this.txtPerPromote.Text.Trim() == "0")
                //    {
                //        frmReportViewer.srptType = "RetailPrintCus";
                //    }
                //    else
                //    {
                //        frmReportViewer.srptType = "RetailPrintCus";
                //    }
                //}
                //frmReportViewer.srptTitle = "HÓA ĐƠN THANH TOÁN";
                //frmReportViewer.TotalBillTable = this.objTable;
                //frmReportViewer.ComName = this.ComName.ToUpper();
                //frmReportViewer.ComPhone = this.ComPhone;
                //frmReportViewer.ComAddress = this.ComAddress;
                //frmReportViewer.RoomName = this.txtCusName.Text.Trim();
                //frmReportViewer.ID = this.txtRetailID.Text.Trim();
                //frmReportViewer.TimeEnd = this.TimeEnd;
                //frmReportViewer.TimeStart = this.TimeStart;
                //frmReportViewer.TimeUse = this.TimeUse;
                //frmReportViewer.VAT = double.Parse(this.txtVAT.Text);
                //frmReportViewer.TotalMoney = double.Parse(this.txtSumAll.Text.Trim());
                //frmReportViewer.RoomMoney = double.Parse(this.txtMoneyRoom.Text);
                //frmReportViewer.TotalPay = double.Parse(this.txtTotalMoney.Text.Trim());
                //frmReportViewer.Promote = double.Parse(this.txtTienKMGH.Text.Trim()) + double.Parse(this.txtMoneyPromote.Text.Trim());
                //if (clsGeneral.ViewAndPrintBill == "False")
                //{
                //    frmReportViewer.setParametes();
                //    frmReportViewer.report.Document.Print(false, true);
                //}
                //else
                //{
                //    frmReportViewer.ShowDialog();
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\nBạn chưa cài máy in.Chức năng này không thể thực hiện được", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void getCompanyInfor()
        {
            string commandText = "SELECT ComName,ComAddress,ComPhone FROM [TabCompany] WHERE [ComID] = 'COM01'";
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = commandText;
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                this.ComName = sqlDataReader["ComName"].ToString();
                this.ComAddress = sqlDataReader["ComAddress"].ToString();
                this.ComPhone = sqlDataReader["ComPhone"].ToString();
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private void CmdAddRows_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtProductID.Text != "" && this.CmdAddRows.Enabled)
                {
                    this.productIndex = this.lvProduct.Items.Count;
                    int num = int.Parse(this.txtDVQD.Text);
                    int num2 = this.CheckItemInList1(this.txtProductID.Text);
                    if (num2 == -1 && this.txtTotalNumber.Text != "")
                    {
                        this.lvProduct.Items.Add(this.txtProductID.Text);
                        this.lvProduct.Items[this.productIndex].SubItems.Add(this.txtProductName.Text);
                        this.lvProduct.Items[this.productIndex].SubItems.Add(this.cbbUnit.Text);
                        this.lvProduct.Items[this.productIndex].SubItems.Add(this.txtNumber.Text);
                        this.lvProduct.Items[this.productIndex].SubItems.Add(this.txtSoLe.Text);
                        this.lvProduct.Items[this.productIndex].SubItems.Add(string.Format("{0:###,0}", num * int.Parse(this.txtNumber.Text.Replace(".", "").Replace(",", "")) + int.Parse(this.txtSoLe.Text.Replace(".", "").Replace(",", ""))));
                        this.lvProduct.Items[this.productIndex].SubItems.Add(string.Format("{0:###,0}", float.Parse(this.txtStandPrice.Text.Replace(".", "").Replace(",", ""))));
                        float num3 = this.AsMoney(num);
                        this.lvProduct.Items[this.productIndex].SubItems.Add(string.Format("{0:###,0}", num3));
                        this.lvProduct.Items[this.productIndex].SubItems.Add(this.cbbUnit.SelectedValue.ToString());
                        this.productIndex++;
                    }
                    else
                    {
                        if (this.txtTotalNumber.Text != "")
                        {
                            this.lvProduct.Items[num2].SubItems[3].Text = (int.Parse(this.lvProduct.Items[num2].SubItems[3].Text) + int.Parse(this.txtNumber.Text)).ToString();
                            this.lvProduct.Items[num2].SubItems[4].Text = (int.Parse(this.lvProduct.Items[num2].SubItems[4].Text) + int.Parse(this.txtSoLe.Text)).ToString();
                            this.lvProduct.Items[num2].SubItems[5].Text = (int.Parse(this.lvProduct.Items[num2].SubItems[5].Text) + int.Parse(this.txtTotalNumber.Text)).ToString();
                            this.lvProduct.Items[num2].SubItems[7].Text = string.Format("{0:###,0}", (float)int.Parse(this.lvProduct.Items[num2].SubItems[5].Text) * float.Parse(this.lvProduct.Items[num2].SubItems[6].Text.Replace(",", "").Replace(".", "")));
                        }
                    }
                    this.txtSumAll.Text = string.Format("{0:###,0}", this.CheckMoney());
                    this.SaveRep(1, this.lblRoomName.Text, int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
            }
            catch
            {
            }
        }
        private float AsMoney(int objDVQD)
        {
            float result = 0f;
            try
            {
                result = (float)(objDVQD * int.Parse(this.txtNumber.Text.Replace(".", "").Replace(",", "")) + int.Parse(this.txtSoLe.Text.Replace(".", "").Replace(",", ""))) * float.Parse(this.txtStandPrice.Text.Replace(".", "").Replace(",", ""));
            }
            catch
            {
            }
            return result;
        }
        private void txtNumber_TextChanged(object sender, EventArgs e)
        {
            if (this.txtProductID.Text.Trim() != "")
            {
                try
                {
                    this.txtTotalNumber.Text = (int.Parse(this.txtNumber.Text.Replace(",", "")) * this.objFunc.GetDVTQD(this.cbbUnit.SelectedValue.ToString()) + int.Parse(this.txtSoLe.Text.Replace(",", ""))).ToString();
                }
                catch
                {
                    this.txtTotalNumber.Text = "0";
                }
            }
        }
        private void txtSoLe_TextChanged(object sender, EventArgs e)
        {
            if (this.txtProductID.Text.Trim() != "")
            {
                try
                {
                    this.txtTotalNumber.Text = (int.Parse(this.txtNumber.Text.Replace(",", "")) * this.objFunc.GetDVTQD(this.cbbUnit.SelectedValue.ToString()) + int.Parse(this.txtSoLe.Text.Replace(",", ""))).ToString();
                }
                catch
                {
                    this.txtTotalNumber.Text = "0";
                }
            }
        }
        private void btnCaculater_Click(object sender, EventArgs e)
        {
            //new frmMyCaculator
            //{
            //    txtMustPay =
            //    {
            //        Text = this.txtMustPay.Text
            //    }
            //}.ShowDialog();
        }
        private void btnShowAll_Click(object sender, EventArgs e)
        {
            this.searchProduct("");
        }
        private void txtSearchFor_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                this.dgvProducts.Focus();
            }
            else
            {
                if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Right)
                {
                    this.txtSetNumber.Focus();
                }
                else
                {
                    if (e.KeyCode == Keys.Escape)
                    {
                        this.listView1.Focus();
                    }
                }
            }
        }
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F4)
            {
                this.txtSearchFor.Text = "";
                this.txtSearchFor.Focus();
            }
            else
            {
                if (e.KeyCode == Keys.F6)
                {
                    this.listView1.Focus();
                }
            }
        }
        private void lblCurrIndex_Click(object sender, EventArgs e)
        {
            if (this.lblCurrIndex.Text == "")
            {
                this.lblCurrIndex.Text = "0";
            }
        }
        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.lblServiceCurrIndex.Text = e.RowIndex.ToString();
                this.txtProductID.Text = this.dgvProducts.Rows[e.RowIndex].Cells[0].Value.ToString();
                if (!this.LoadingFlag)
                {
                    if (this.dgvProducts.Rows[e.RowIndex].Cells["DVT"].Value.ToString() != "")
                    {
                        this.txtSearchFor.Text = this.dgvProducts.Rows[e.RowIndex].Cells[1].Value.ToString();
                        this.txtProductName.Text = this.dgvProducts.Rows[e.RowIndex].Cells[1].Value.ToString();
                    }
                    else
                    {
                        this.txtSearchFor.Text = "";
                        this.txtProductName.Text = "";
                    }
                }
                try
                {
                    this.cbbUnit.SelectedValue = this.dgvProducts.Rows[e.RowIndex].Cells[2].Value.ToString();
                }
                catch
                {
                }
                if (this.objTime.Contains("\"" + DateTime.Now.Hour.ToString() + "\""))
                {
                    float num = float.Parse(this.dgvProducts.Rows[e.RowIndex].Cells[3].Value.ToString());
                    this.txtStandPrice.Text = string.Format("{0:###,0}", num - num * this.discount / 100f);
                }
                else
                {
                    float num = float.Parse(this.dgvProducts.Rows[e.RowIndex].Cells[4].Value.ToString());
                    this.txtStandPrice.Text = string.Format("{0:###,0}", num - num * this.discount / 100f);
                }
                if (this.dgvProducts.Rows[e.RowIndex].Cells[5].Value.ToString() == "0")
                {
                    this.txtNumber.Text = "0";
                    this.txtSoLe.Text = "1";
                    this.txtTotalNumber.Text = "1";
                }
                else
                {
                    this.txtNumber.Text = "1";
                    this.txtSoLe.Text = "0";
                    this.txtTotalNumber.Text = int.Parse(this.dgvProducts.Rows[e.RowIndex].Cells[6].Value.ToString()).ToString();
                }
                this.txtDVQD.Text = this.dgvProducts.Rows[e.RowIndex].Cells[6].Value.ToString();
                float num2 = float.Parse(this.txtTotalNumber.Text.Replace(".", "").Replace(",", "")) * float.Parse(this.txtStandPrice.Text.Replace(".", "").Replace(",", ""));
            }
            catch
            {
            }
        }
        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                if (this.CmdAddRows.Enabled)
                {
                    this.txtSearchFor.Text = this.txtProductName.Text;
                    this.txtSetNumber.Focus();
                }
            }
            else
            {
                if (e.KeyCode == Keys.Up && this.lblServiceCurrIndex.Text == "0")
                {
                    this.txtSearchFor.Focus();
                }
                else
                {
                    if (e.KeyCode == Keys.Down && this.lblServiceCurrIndex.Text == this.dgvProducts.RowCount.ToString())
                    {
                        this.txtSearchFor.Focus();
                    }
                    else
                    {
                        if (e.KeyCode == Keys.Left)
                        {
                            this.listView1.Focus();
                        }
                        else
                        {
                            if (e.KeyCode == Keys.Escape)
                            {
                                this.listView1.Focus();
                            }
                            else
                            {
                                if (e.KeyCode == Keys.N)
                                {
                                    //FrmupdtProduct frmupdtProduct = new FrmupdtProduct();
                                    //frmupdtProduct.closeAffterSave = true;
                                    //frmupdtProduct.ShowDialog();
                                    //if (frmupdtProduct.txtName.Text != "")
                                    //{
                                    //    this.txtSearchFor.Text = frmupdtProduct.txtName.Text;
                                    //    this.searchProductAffterAdd(frmupdtProduct.txtName.Text);
                                    //    if (this.dgvProducts.RowCount > 1)
                                    //    {
                                    //        this.dgvProducts.Rows[1].Selected = true;
                                    //    }
                                    //}
                                }
                                else
                                {
                                    if (e.KeyCode == Keys.E)
                                    {
                                        if (this.txtProductID.Text != "")
                                        {
                                            //FrmupdtProduct frmupdtProduct = new FrmupdtProduct();
                                            //frmupdtProduct.closeAffterSave = true;
                                            //frmupdtProduct.ProductID = int.Parse(this.txtProductID.Text);
                                            //frmupdtProduct.ShowDialog();
                                            //if (frmupdtProduct.txtName.Text != "")
                                            //{
                                            //    this.txtSearchFor.Text = frmupdtProduct.txtName.Text;
                                            //    this.searchProductAffterAdd(frmupdtProduct.txtName.Text);
                                            //    if (this.dgvProducts.RowCount > 1)
                                            //    {
                                            //        this.dgvProducts.Rows[1].Selected = true;
                                            //    }
                                            //}
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.CmdAddRows.Enabled && this.lblRoomName.Text.Trim() != "")
            {
                this.CmdAddRows.PerformClick();
            }
        }
        private void txtPerPromote_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
            if (e.KeyChar == '\r')
            {
                try
                {
                    float.Parse(this.txtPerPromote.Text);
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void calKmDV()
        {
            if (this.calByPercent != 0)
            {
                double num = 0.0;
                double num2 = 0.0;
                double money = 0.0;
                try
                {
                    num = double.Parse(this.txtSumAll.Text.Trim());
                }
                catch
                {
                    num = 0.0;
                }
                try
                {
                    num2 = double.Parse(this.txtPerPromote.Text.Trim());
                }
                catch
                {
                    num2 = 0.0;
                }
                try
                {
                    money = num * num2 / 100.0;
                }
                catch
                {
                    money = 0.0;
                }
                this.txtMoneyPromote.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(money, clsGeneral.roundValue));
                if (num2 < 0.0 || num2 > 100.0)
                {
                    MessageBox.Show("Khuyến mãi không chính xác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    this.txtPerPromote.Text = "0";
                    this.txtPerPromote.Focus();
                }
            }
        }
        private void txtPerPromote_TextChanged(object sender, EventArgs e)
        {
            this.calKmDV();
            this.calTotalMoney();
        }
        private void calKmGH()
        {
            if (this.calByPercent != 0)
            {
                double num = 0.0;
                double num2 = 0.0;
                double money = 0.0;
                try
                {
                    num = double.Parse(this.txtMoneyRoom.Text.Trim());
                }
                catch
                {
                    num = 0.0;
                }
                try
                {
                    num2 = double.Parse(this.txtKmGH.Text.Trim());
                }
                catch
                {
                    num2 = 0.0;
                }
                try
                {
                    money = num * num2 / 100.0;
                }
                catch
                {
                    money = 0.0;
                }
                this.txtTienKMGH.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(money, clsGeneral.roundValue));
                double num3 = 0.0;
                double num4 = 0.0;
                double money2 = 0.0;
                try
                {
                    num3 = double.Parse(this.txtSumAll.Text.Trim());
                }
                catch
                {
                    num3 = 0.0;
                }
                try
                {
                    num4 = double.Parse(this.txtPerPromote.Text.Trim());
                }
                catch
                {
                    num4 = 0.0;
                }
                try
                {
                    money2 = num3 * num4 / 100.0;
                }
                catch
                {
                    money2 = 0.0;
                }
                this.txtMoneyPromote.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(money2, clsGeneral.roundValue));
                if (num2 < 0.0 || num2 > 100.0)
                {
                    MessageBox.Show("Khuyến mãi không chính xác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    this.txtKmGH.Text = "0";
                    this.txtKmGH.Focus();
                }
            }
        }
        private void txtKmGH_TextChanged(object sender, EventArgs e)
        {
            this.calKmGH();
            this.calTotalMoney();
        }
        private void tMnuNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }
        private void txtSoLe_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space)
            {
                this.CmdAddRows.PerformClick();
            }
        }
        private void txtSetNumber_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int.Parse(this.txtSetNumber.Text);
                this.txtSoLe.Text = this.txtSetNumber.Text;
            }
            catch
            {
                this.txtSoLe.Text = "1";
            }
        }
        private void txtSetNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                if (this.CmdAddRows.Enabled && this.lblRoomName.Text.Trim() != "")
                {
                    this.CmdAddRows.PerformClick();
                    this.txtSetNumber.Text = "";
                    this.txtSearchFor.Text = "";
                    this.txtSearchFor.Focus();
                }
                else
                {
                    MessageBox.Show("Có thể bạn chưa chọn đối tượng để cung cấp dịch vụ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.listView1.Focus();
                }
            }
        }
        private void txtSearchFor_TextChanged(object sender, EventArgs e)
        {
            if (this.LoadingFlag)
            {
                this.searchProduct(this.txtSearchFor.Text);
            }
        }
        private void txtKmGH_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
            if (e.KeyChar == '\r')
            {
                try
                {
                    float.Parse(this.txtKmGH.Text);
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void btnEditTime_Click(object sender, EventArgs e)
        {
            if (this.objFunc.CheckPerDetailt("EDITTIME", this.UserName))
            {
                if (this.btnEditTime.Text == "Bỏ")
                {
                    int tmpIndex = int.Parse(this.lblCurrIndex.Text);
                    this.btnSaveEditTime.Enabled = false;
                    this.lvProduct.Enabled = true;
                    this.CmdAddRows.Enabled = true;
                    this.TPTimeStart.Enabled = false;
                    this.listView1.Enabled = true;
                    this.dgvProducts.Enabled = true;
                    this.FocusWhenStart(tmpIndex);
                    this.TPTimeStart.Focus();
                }
                else
                {
                    this.btnSaveEditTime.Enabled = true;
                    this.TPTimeStart.Enabled = true;
                    this.listView1.Enabled = false;
                    this.lvProduct.Enabled = false;
                    this.dgvProducts.Enabled = false;
                    this.CmdAddRows.Enabled = false;
                    this.listView1.Focus();
                }
            }
            else
            {
                MessageBox.Show("Bạn không có quyền thực hiện chức năng này !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void TPTimeStart_ValueChanged(object sender, EventArgs e)
        {
            if (this.btnSaveEditTime.Enabled)
            {
                DateTime dateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
                if (this.CurrentRoomChanged == 0)
                {
                    int num = (int)dateTime.Subtract(this.TPTimeStart.Value).TotalMinutes - this.objRoom.getMinitePause(int.Parse(this.currRoomID));
                    this.txtTimeUse.Text = num.ToString() + " Phút";
                    double money = (double)((float)num * this.RoomPrice);
                    this.txtMoneyRoom.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(money, clsGeneral.roundValue));
                }
                else
                {
                    TimeSpan timeSpan = dateTime.Subtract(this.CurrRoomTimeStart);
                    int num = (int)dateTime.Subtract(this.TPTimeStart.Value).TotalMinutes - this.objRoom.getMinitePause(int.Parse(this.currRoomID));
                    int num2 = (int)timeSpan.TotalMinutes;
                    int num3 = num - num2;
                    this.RoomStartRealNew = this.RoomStartDateTimeReal.AddMinutes((double)(-(double)num3));
                    int num4 = (int)dateTime.Subtract(this.RoomStartRealNew).TotalMinutes - this.objRoom.getMinitePause(int.Parse(this.currRoomID));
                    this.txtTimeUse.Text = num.ToString() + " Phút";
                    double money = (double)((float)num4 * this.RoomPrice + this.MoneyRoomChanged);
                    this.txtMoneyRoom.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(money, clsGeneral.roundValue));
                }
            }
        }
        private void btnSaveEditTime_Click(object sender, EventArgs e)
        {
            int tmpIndex = int.Parse(this.lblCurrIndex.Text);
            if (MessageBox.Show("Bạn có muốn thay đổi giờ vào cho sân " + this.lblRoomName.Text.ToUpper() + "  không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand("AlterTimeStartOnTabRoomRent", sqlConnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@RoomID", SqlDbType.Int);
                sqlCommand.Parameters.Add("@TimeStart", SqlDbType.DateTime);
                sqlCommand.Parameters.Add("@TimeReal", SqlDbType.DateTime);
                sqlCommand.Parameters.Add("@StatusPriceRoomChanged", SqlDbType.SmallInt);
                sqlCommand.Parameters["@RoomID"].Value = int.Parse(this.currRoomID);
                sqlCommand.Parameters["@TimeStart"].Value = this.TPTimeStart.Value;
                sqlCommand.Parameters["@TimeReal"].Value = this.RoomStartRealNew;
                sqlCommand.Parameters["@StatusPriceRoomChanged"].Value = this.CurrentRoomChanged;
                sqlCommand.ExecuteNonQuery();
            }
            this.ReFresh();
            this.SaveLog(this.txtCusName.Text, 4);
            this.FocusWhenStart(tmpIndex);
            this.btnSaveEditTime.Enabled = false;
            this.lvProduct.Enabled = true;
            this.CmdAddRows.Enabled = true;
            this.TPTimeStart.Enabled = false;
            this.listView1.Enabled = true;
            this.dgvProducts.Enabled = true;
        }
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar) && e.KeyChar != '.' && e.KeyChar != ',')
            {
                e.Handled = true;
            }
            if (e.KeyChar == '\r')
            {
                try
                {
                    double.Parse(this.txtVAT.Text);
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void txtMoneyAfterVAT_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
        private void LoadProvider()
        {
            this.cbbCustomer.Items.Clear();
            this.cbbCustomer.BindingContext = new BindingContext();
            this.cbbCustomer.Items.Add(new ItemCombobox("               ", "0"));
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            SqlCommand sqlCommand = new SqlCommand("SELECT ID,Name FROM tblPartner WHERE TypePartner=0  ORDER BY Name", sqlConnection);
            sqlConnection.Open();
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                this.cbbCustomer.Items.Add(new ItemCombobox(sqlDataReader["Name"].ToString(), sqlDataReader["ID"].ToString()));
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
            this.cbbCustomer.SelectedIndex = 0;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //frmDir frmDir = new frmDir();
            //frmDir.sTabTable = "KHÁCH HÀNG";
            //frmDir.FormBorderStyle = FormBorderStyle.Sizable;
            //frmDir.ForSelectPartner = true;
            //frmDir.PartnerType = "0";
            //frmDir.ShowDialog();
            //if (frmDir._Name.Trim() != "")
            //{
            //    this.LoadProvider();
            //    this.objFunc.SelectValueCombobox(this.cbbCustomer, frmDir._ID);
            //    try
            //    {
            //        this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
            //    }
            //    catch
            //    {
            //    }
            //}
        }
        private void TextBoxTextChanged(object sender, EventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text.Trim().Length > 3)
            {
                try
                {
                    textBox.Text = string.Format("{0:###,0}", double.Parse(textBox.Text));
                    textBox.SelectionStart = textBox.Text.Trim().Length;
                }
                catch
                {
                }
            }
        }
        private void LoadPromoteForCus(string CusID)
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = "select ISNULL(PromoteTime,0) AS PromoteTime,ISNULL(PromoteAll,0) AS PromoteAll from tblPartner where ID=" + CusID;
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            if (sqlDataReader.HasRows)
            {
                while (sqlDataReader.Read())
                {
                    this.txtKmGH.Text = string.Format("{0:###,0}", double.Parse(sqlDataReader["PromoteTime"].ToString()));
                    this.txtPerPromote.Text = string.Format("{0:###,0}", double.Parse(sqlDataReader["PromoteAll"].ToString()));
                }
            }
            sqlDataReader.Close();
            sqlDataReader.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private void cbbCustomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                ItemCombobox itemCombobox = (ItemCombobox)this.cbbCustomer.SelectedItem;
                if (itemCombobox.Value == "0")
                {
                    this.txtTotalPay.ReadOnly = true;
                }
                else
                {
                    this.txtTotalPay.ReadOnly = false;
                    this.LoadPromoteForCus(itemCombobox.Value);
                }
                this.calTotalMoney();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void txtTotalPay_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                try
                {
                    this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                }
                catch
                {
                }
            }
        }
        private void btnSaveCus_Click(object sender, EventArgs e)
        {
            try
            {
                this.calTotalMoney();
                this.SaveRep(1, this.lblRoomName.Text.Trim(), int.Parse(this.lblCurrIndex.Text), this.currRoomID, false);
                this.getNumVip();
            }
            catch
            {
            }
        }
        private void LoadDataImg()
        {
            try
            {
                this.imageList1.Images.Clear();
                string startupPath = Application.StartupPath;
                Image value = Image.FromFile(startupPath + "\\Img1.jpg");
                this.imageList1.Images.Add(value);
                value = Image.FromFile(startupPath + "\\Img0.jpg");
                this.imageList1.Images.Add(value);
                value = Image.FromFile(startupPath + "\\Img2.jpg");
                this.imageList1.Images.Add(value);
            }
            catch
            {
            }
        }
        private void recalCaculatorMoney()
        {
            double num = 0.0;
            double num2 = 0.0;
            double num3 = 0.0;
            try
            {
                num = double.Parse(this.txtMoneyRoom.Text.Trim());
            }
            catch
            {
                num = 0.0;
            }
            try
            {
                num2 = (double)float.Parse(this.txtKmGH.Text.Trim());
            }
            catch
            {
                num2 = 0.0;
            }
            try
            {
                num3 = num * num2 / 100.0;
            }
            catch
            {
                num3 = 0.0;
            }
            this.txtTienKMGH.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(num3, clsGeneral.roundValue));
            double num4 = 0.0;
            double num5 = 0.0;
            double num6 = 0.0;
            try
            {
                num4 = double.Parse(this.txtSumAll.Text.Trim());
            }
            catch
            {
                num4 = 0.0;
            }
            try
            {
                num5 = double.Parse(this.txtPerPromote.Text.Trim());
            }
            catch
            {
                num5 = 0.0;
            }
            try
            {
                num6 = num4 * num5 / 100.0;
            }
            catch
            {
                num6 = 0.0;
            }
            this.txtMoneyPromote.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(num6, clsGeneral.roundValue));
            double money = double.Parse(this.txtMustPay.Text.Trim()) - num6 - num3;
            this.txtTotalMoney.Text = string.Format("{0:###,0}", clsGeneral.roundMoney(money, clsGeneral.roundValue));
            if (num2 < 0.0 || num2 > 100.0)
            {
                MessageBox.Show("Khuyến mãi không chính xác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.txtKmGH.Text = "0";
                this.txtKmGH.Focus();
            }
        }
        private void txtSearchFor_Enter(object sender, EventArgs e)
        {
            this.txtSearchFor.BackColor = Color.Aqua;
            this.LoadingFlag = true;
        }
        private void txtSearchFor_Leave(object sender, EventArgs e)
        {
            this.txtSearchFor.BackColor = Color.White;
            this.LoadingFlag = false;
        }
        private void txtSetNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                this.txtSearchFor.Focus();
            }
            else
            {
                if (e.KeyCode == Keys.Down)
                {
                    this.dgvProducts.Focus();
                }
                else
                {
                    if (e.KeyCode == Keys.Escape)
                    {
                        this.listView1.Focus();
                    }
                }
            }
        }
        private void dgvProducts_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            if (this.dgvProducts.Rows[e.RowIndex].Cells["Column1"].Value.ToString() == "")
            {
                this.dgvProducts.Rows[e.RowIndex].Cells[0].Style = this.objRowColor;
                this.dgvProducts.Rows[e.RowIndex].Cells[1].Style = this.objRowColor;
                this.dgvProducts.Rows[e.RowIndex].Cells[1].Style.Font = new Font("Arial", 9f, FontStyle.Bold);
                this.dgvProducts.Rows[e.RowIndex].Cells[1].Style.ForeColor = Color.Blue;
                this.dgvProducts.Rows[e.RowIndex].Cells[2].Style = this.objRowColor;
                this.dgvProducts.Rows[e.RowIndex].Cells[3].Style = this.objRowColor;
                this.dgvProducts.Rows[e.RowIndex].Cells[4].Style = this.objRowColor;
                this.dgvProducts.Rows[e.RowIndex].Cells[5].Style = this.objRowColor;
                this.dgvProducts.Rows[e.RowIndex].Cells[6].Style = this.objRowColor;
            }
        }
        private void getOtherMoney()
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = "SELECT OtherMoney, calByPercent FROM TabConfig";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                if (sqlDataReader["calByPercent"].ToString() == "1")
                {
                    this.txtOtherPercent.Text = sqlDataReader["OtherMoney"].ToString();
                }
                else
                {
                    this.txtOrtherMoney.Text = string.Format("{0:0,0}", clsGeneral.roundMoney(double.Parse(sqlDataReader["OtherMoney"].ToString()), clsGeneral.roundValue));
                }
            }
            sqlDataReader.Close();
            sqlConnection.Close();
            sqlConnection.Dispose();
        }
        private void getCalByPercent()
        {
            SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = "SELECT ISNULL(calByPercent,0) as calByPercent FROM TabConfig";
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            while (sqlDataReader.Read())
            {
                this.calByPercent = int.Parse(sqlDataReader["calByPercent"].ToString());
            }
            sqlDataReader.Close();
            sqlConnection.Close();
            sqlConnection.Dispose();
            if (this.calByPercent == 1)
            {
                this.txtOtherPercent.ReadOnly = false;
                this.txtKmGH.ReadOnly = false;
                this.txtTienKMGH.ReadOnly = true;
                this.txtPerPromote.ReadOnly = false;
                this.txtMoneyPromote.ReadOnly = true;
            }
            else
            {
                this.txtOtherPercent.ReadOnly = true;
                this.txtKmGH.ReadOnly = true;
                this.txtTienKMGH.ReadOnly = false;
                this.txtPerPromote.ReadOnly = true;
                this.txtMoneyPromote.ReadOnly = false;
            }
        }
        private void txtOtherPercent_DoubleClick(object sender, EventArgs e)
        {
            this.getOtherMoney();
        }
        private void calTotalMoney()
        {
            if (this.txtOtherPercent.Text == "")
            {
                this.txtOtherPercent.Text = "0";
            }
            try
            {
                double num2;
                if (this.calByPercent == 1)
                {
                    double num = double.Parse(this.txtOtherPercent.Text);
                    num2 = num * (double.Parse(this.txtSumAll.Text) + double.Parse(this.txtMoneyRoom.Text)) / 100.0;
                    this.txtOrtherMoney.Text = string.Format("{0:0,0}", clsGeneral.roundMoney(num2, clsGeneral.roundValue));
                }
                else
                {
                    num2 = double.Parse(this.txtOrtherMoney.Text);
                }
                this.txtMustPay.Text = string.Format("{0:0,0}", double.Parse(this.txtSumAll.Text) + double.Parse(this.txtMoneyRoom.Text) + num2);
                this.calKmDV();
                this.calKmGH();
                this.txtTotalMoney.Text = string.Format("{0:0,0}", double.Parse(this.txtMustPay.Text) - double.Parse(this.txtTienKMGH.Text) - double.Parse(this.txtMoneyPromote.Text));
                this.calVAT();
                this.txtTotalPay.Text = string.Format("{0:0,0}", double.Parse(this.txtTotalMoney.Text) + double.Parse(this.txtMoneyAfterVAT.Text));
            }
            catch
            {
                MessageBox.Show("Phần trăm phụ thu không đúng định dạng !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txtOtherPercent.Text = "0";
                this.txtOrtherMoney.Text = "0";
                this.txtOtherPercent.SelectAll();
                this.txtOtherPercent.Focus();
            }
        }
        private void txtOtherPercent_TextChanged(object sender, EventArgs e)
        {
            this.calTotalMoney();
        }
        private void calVAT()
        {
            if (this.txtVAT.Text == "")
            {
                this.txtVAT.Text = "0";
            }
            try
            {
                double num = double.Parse(this.txtVAT.Text);
                double money = num * double.Parse(this.txtTotalMoney.Text) / 100.0;
                this.txtMoneyAfterVAT.Text = string.Format("{0:0,0}", clsGeneral.roundMoney(money, clsGeneral.roundValue));
            }
            catch
            {
                MessageBox.Show("Giá trị thuế VAT không đúng định dạng !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txtVAT.Text = "0";
                this.txtVAT.SelectAll();
                this.txtVAT.Focus();
            }
        }
        private void txtVAT_TextChanged(object sender, EventArgs e)
        {
            this.calVAT();
            this.calTotalMoney();
        }
        private void txtMoneyRoom_TextChanged(object sender, EventArgs e)
        {
            this.calTotalMoney();
        }
        private void txtMustPay_TextChanged(object sender, EventArgs e)
        {
            this.calTotalMoney();
        }
        private void txtSumAll_TextChanged(object sender, EventArgs e)
        {
            this.calTotalMoney();
        }
        private void dgvProducts_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                Rectangle cellDisplayRectangle = this.dgvProducts.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
                this.toolTip1.Show("Nháp đúp chuột để chọn dịch vụ !\r\nHoặc nếu muốn thực hiện các tác vụ khác", this, this.dgvProducts.Location.X + cellDisplayRectangle.X + cellDisplayRectangle.Size.Width, this.dgvProducts.Location.Y + cellDisplayRectangle.Y + cellDisplayRectangle.Size.Height, 5000);
            }
            else
            {
                if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
                {
                    this.toolTip1.Hide(this);
                    this.dgvProducts.Rows[e.RowIndex].Cells[e.ColumnIndex].ToolTipText = "Nháp đúp chuột để chọn dịch vụ cho sân hiện tại!";
                }
            }
        }
        private void mnuRoomInfo_Click(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                //new frmRoomInfor
                //{
                //    lblRoomName =
                //    {
                //        Text = array[0]
                //    },
                //    currRoomId = this.currRoomID
                //}.ShowDialog();
            }
            catch
            {
            }
        }
        private void txtOrtherMoney_TextChanged(object sender, EventArgs e)
        {
            if (this.calByPercent == 0)
            {
                try
                {
                    double num = double.Parse(this.txtOrtherMoney.Text);
                    if (double.Parse(this.txtSumAll.Text) + double.Parse(this.txtMoneyRoom.Text) > 0.0)
                    {
                        double num2 = 100.0 * num / (double.Parse(this.txtSumAll.Text) + double.Parse(this.txtMoneyRoom.Text));
                        this.txtOtherPercent.Text = num2.ToString();
                    }
                    else
                    {
                        this.txtOtherPercent.Text = "0";
                    }
                    this.calTotalMoney();
                }
                catch
                {
                    this.txtOtherPercent.Text = "0";
                }
            }
        }
        private void txtTienKMGH_TextChanged(object sender, EventArgs e)
        {
            this.calTienKMGH();
        }
        private void calTienKMGH()
        {
            double num = 0.0;
            if (this.calByPercent == 0)
            {
                try
                {
                    double num2 = double.Parse(this.txtTienKMGH.Text);
                    if (double.Parse(this.txtMoneyRoom.Text) > 0.0)
                    {
                        num = 100.0 * num2 / double.Parse(this.txtMoneyRoom.Text);
                    }
                    else
                    {
                        this.txtKmGH.Text = "0";
                    }
                    this.txtKmGH.Text = num.ToString();
                    this.calTotalMoney();
                }
                catch
                {
                    this.txtKmGH.Text = "0";
                }
            }
        }
        private void txtMoneyPromote_TextChanged(object sender, EventArgs e)
        {
            this.moneyPromote();
        }
        private void moneyPromote()
        {
            double num = 0.0;
            if (this.calByPercent == 0)
            {
                try
                {
                    double num2 = double.Parse(this.txtMoneyPromote.Text);
                    if (double.Parse(this.txtSumAll.Text) > 0.0)
                    {
                        num = 100.0 * num2 / double.Parse(this.txtSumAll.Text);
                    }
                    else
                    {
                        this.txtPerPromote.Text = "0";
                    }
                    this.txtPerPromote.Text = num.ToString();
                    this.calTotalMoney();
                }
                catch
                {
                    this.txtPerPromote.Text = "0";
                }
            }
        }
        private void mnuAddRoom_Click(object sender, EventArgs e)
        {
            if (this.Permission.Contains("21"))
            {
                //new FrmudtRoom
                //{
                //    txtGCustomer_ID =
                //    {
                //        Text = "0"
                //    }
                //}.ShowDialog();
            }
            else
            {
                MessageBox.Show("Bạn không có quyền thực hiện nhiệm vụ này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void cmsAddGroupProduct_Click(object sender, EventArgs e)
        {
            if (this.Permission.Contains("21"))
            {
                //FrmupdtGproduct frmupdtGproduct = new FrmupdtGproduct();
                //frmupdtGproduct.ShowDialog();
            }
            else
            {
                MessageBox.Show("Bạn không có quyền thực hiện nhiệm vụ này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void cmsAddProduct_Click(object sender, EventArgs e)
        {
            if (this.Permission.Contains("21"))
            {
                //FrmupdtProduct frmupdtProduct = new FrmupdtProduct();
                //frmupdtProduct.ShowDialog();
                //if (frmupdtProduct.isSaved)
                //{
                //    this.searchProduct("");
                //}
            }
            else
            {
                MessageBox.Show("Bạn không có quyền thực hiện nhiệm vụ này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void getNumVip()
        {
            try
            {
                SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
                sqlConnection.Open();
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText = "SELECT ISNULL(COUNT(PartnerID),0) AS NumVip FROM TabRetailsList WHERE RetailID IN (SELECT RepID FROM TabRoomRent WHERE Status = 1) AND PartnerID <> 0 AND PartnerID IN (SELECT ID FROM tblPartner WHERE IsVip = 1)";
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    this.btnVipCounter.Text = "VIP  " + sqlDataReader["NumVip"].ToString();
                }
                sqlDataReader.Close();
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
            catch
            {
            }
        }
        private void btnVipCounter_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.btnVipCounter.Text.Trim() == "VIP 0")
                {
                    MessageBox.Show("Không có khách VIP trong danh sách !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    //frmViewListVip frmViewListVip = new frmViewListVip();
                    //frmViewListVip.ShowDialog();
                }
            }
            catch
            {
            }
        }
        private void txtSetNumber_Enter(object sender, EventArgs e)
        {
            this.txtSetNumber.BackColor = Color.Aqua;
        }
        private void lvProduct_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.listView1.Focus();
            }
        }
        private void tsMnuPause_Click(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                if (MessageBox.Show(string.Concat(new string[]
				{
					"Bạn có muốn ",
					this.tsMnuPause.Text.ToLower(),
					" sân ",
					this.lblRoomName.Text.ToUpper(),
					" không?"
				}), "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.txtRetailID.Text = this.objR.getRepID(this.currRoomID);
                    this.objRoom.setPause(this.txtRetailID.Text, int.Parse(this.currRoomID), DateTime.Now, DateTime.Now);
                    this.ReFresh();
                }
            }
            catch
            {
            }
        }
        private void mnuPayment_Click(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                if (this.objRoom.checkRoomPause(int.Parse(this.currRoomID)))
                {
                    MessageBox.Show("Sân đang bị tạm dừng sử dụng\r\n\r\nBạn hãy tiếp tục sử dụng trước khi thanh toán !", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    if (MessageBox.Show("Bạn có muốn thanh toán tiền cho sân " + this.lblRoomName.Text.ToUpper() + " không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.objRoom.finishAllPause(int.Parse(this.currRoomID));
                        this.CloseRoom(this.currRoomID, index);
                        this.btnSaveCus.PerformClick();
                        this.Pay(this.currRoomID, index, this.lblRoomName.Text, false);
                    }
                }
            }
            catch
            {
            }
        }
        private void btnEmp_Click(object sender, EventArgs e)
        {
            if (this.CmdAddRows.Enabled && this.lblRoomName.Text.Trim() != "")
            {
                if (this.txtRetailID.Text == "")
                {
                    this.btnSaveCus.PerformClick();
                }
                //frmSelectEmp frmSelectEmp = new frmSelectEmp();
                //frmSelectEmp.ShowDialog();
                //this.btnEmp.Text = "PV : " + frmSelectEmp.empName;
                //this.objRoom.setEmpId(frmSelectEmp.empId, this.txtRetailID.Text);
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn sân cần phục vụ !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.listView1.Focus();
            }
        }
        private void mnuRename_Click(object sender, EventArgs e)
        {
            try
            {
                int index = this.listView1.FocusedItem.Index;
                this.lblCurrIndex.Text = this.listView1.FocusedItem.Index.ToString();
                string[] array = this.listView1.Items[int.Parse(this.lblCurrIndex.Text)].SubItems[0].Text.Split(new char[]
				{
					'-'
				});
                this.lblRoomName.Text = array[0];
                this.currRoomID = this.RoomID[int.Parse(this.lblCurrIndex.Text)].ToString();
                //FrmudtRoom frmudtRoom = new FrmudtRoom();
                //frmudtRoom._GCustomer_ID = this.currRoomID;
                //frmudtRoom.ShowDialog();
                //if (frmudtRoom.isSaved)
                //{
                //    this.ReFresh();
                //}
            }
            catch
            {
            }
        }
        private void mnuSelect_Click(object sender, EventArgs e)
        {
            if (this.CmdAddRows.Enabled && this.lblRoomName.Text.Trim() != "")
            {
                this.CmdAddRows.PerformClick();
            }
        }
        private void cmsEditProduct_Click(object sender, EventArgs e)
        {
            if (this.Permission.Contains("21"))
            {
                if (this.txtProductID.Text != "")
                {
                    //FrmupdtProduct frmupdtProduct = new FrmupdtProduct();
                    //frmupdtProduct.ProductID = int.Parse(this.txtProductID.Text);
                    //frmupdtProduct.ShowDialog();
                    //if (frmupdtProduct.isSaved)
                    //{
                    //    this.searchProduct("");
                    //}
                }
            }
            else
            {
                MessageBox.Show("Bạn không có quyền thực hiện nhiệm vụ này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    }
}
